Submission #69714620
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=(a);i<(n);i++)
#define per(i,a,n) for (int i=(n)-1;i>=(a);i--)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef basic_string<int> BI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
template<int MOD, int RT> struct mint {
static const int mod = MOD;
static constexpr mint rt() { return RT; } // primitive root for FFT
int v; explicit operator int() const { return v; } // explicit -> don't silently convert to int
mint():v(0) {}
mint(ll _v) { v = int((-MOD < _v && _v < MOD) ? _v : _v % MOD);
if (v < 0) v += MOD; }
bool operator==(const mint& o) const {
return v == o.v; }
friend bool operator!=(const mint& a, const mint& b) {
return !(a == b); }
friend bool operator<(const mint& a, const mint& b) {
return a.v < b.v; }
mint& operator+=(const mint& o) {
if ((v += o.v) >= MOD) v -= MOD;
return *this; }
mint& operator-=(const mint& o) {
if ((v -= o.v) < 0) v += MOD;
return *this; }
mint& operator*=(const mint& o) {
v = int((ll)v*o.v%MOD); return *this; }
mint& operator/=(const mint& o) { return (*this) *= inv(o); }
friend mint pow(mint a, ll p) {
mint ans = 1; assert(p >= 0);
for (; p; p /= 2, a *= a) if (p&1) ans *= a;
return ans; }
friend mint inv(const mint& a) { assert(a.v != 0);
return pow(a,MOD-2); }
mint operator-() const { return mint(-v); }
mint& operator++() { return *this += 1; }
mint& operator--() { return *this -= 1; }
friend mint operator+(mint a, const mint& b) { return a += b; }
friend mint operator-(mint a, const mint& b) { return a -= b; }
friend mint operator*(mint a, const mint& b) { return a *= b; }
friend mint operator/(mint a, const mint& b) { return a /= b; }
};
const int MOD=998244353;
using mi = mint<MOD,5>; // 5 is primitive root for both common mods
namespace simp {
vector<mi> fac,ifac,invn;
void check(int x) {
assert(mod==MOD);
if (fac.empty()) {
fac={mi(1),mi(1)};
ifac={mi(1),mi(1)};
invn={mi(0),mi(1)};
}
while (SZ(fac)<=x) {
int n=SZ(fac),m=SZ(fac)*2;
fac.resize(m);
ifac.resize(m);
invn.resize(m);
for (int i=n;i<m;i++) {
fac[i]=fac[i-1]*mi(i);
invn[i]=mi(MOD-MOD/i)*invn[MOD%i];
ifac[i]=ifac[i-1]*invn[i];
}
}
}
mi gfac(int x) {
assert(x>=0);
check(x); return fac[x];
}
mi ginv(int x) {
assert(x>0);
check(x); return invn[x];
}
mi gifac(int x) {
assert(x>=0);
check(x); return ifac[x];
}
mi binom(int n,int m) {
if (m < 0 || m > n) return mi(0);
return gfac(n)*gifac(m)*gifac(n - m);
}
mi binombf(int n,int m) {
if (m < 0 || m > n) return mi(0);
if (m>n-m) m=n-m;
mi p=1,q=1;
for (int i=1;i<=m;i++) p=p*(n+1-i),q=q*i;
return p/q;
}
}
const int N=501000;
int l,k,n;
int a[N];
mi pw[N],ans;
int main() {
scanf("%d%d%d",&l,&k,&n);
rep(i,0,n) scanf("%d",&a[i]);
pw[0]=1;
rep(i,1,n+1) pw[i]=pw[i-1]*2;
rep(i,0,n) a[i+n]=a[i]+l;
ans+=n*pw[n-1];
rep(l,0,n) {
int R=lower_bound(a,a+2*n,a[l]+k)-a-1;
R=min(R,l+n-1);
if (R>=l+2) ans+=(R-l-1)*pw[n-3];
/*rep(r,l+2,l+n) if (a[r]<a[l]+k) {
ans+=pw[n-3];
}*/
}
printf("%d\n",(int)ans);
}
Submission Info
| Submission Time |
|
| Task |
A - Chords and Checkered |
| User |
apiad |
| Language |
C++ 20 (gcc 12.2) |
| Score |
700 |
| Code Size |
3699 Byte |
| Status |
AC |
| Exec Time |
35 ms |
| Memory |
7784 KiB |
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:117:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
117 | scanf("%d%d%d",&l,&k,&n);
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:118:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
118 | rep(i,0,n) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
700 / 700 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt |
| All |
00-sample-001.txt, 00-sample-002.txt, 00-sample-003.txt, 00-sample-004.txt, 01-001.txt, 01-002.txt, 01-003.txt, 01-004.txt, 01-005.txt, 01-006.txt, 01-007.txt, 01-008.txt, 01-009.txt, 01-010.txt, 01-011.txt, 01-012.txt, 01-013.txt, 01-014.txt, 01-015.txt, 01-016.txt, 01-017.txt, 01-018.txt, 01-019.txt, 01-020.txt, 01-021.txt, 01-022.txt, 01-023.txt, 01-024.txt, 01-025.txt, 01-026.txt, 01-027.txt, 01-028.txt |
| Case Name |
Status |
Exec Time |
Memory |
| 00-sample-001.txt |
AC |
2 ms |
5644 KiB |
| 00-sample-002.txt |
AC |
2 ms |
5644 KiB |
| 00-sample-003.txt |
AC |
2 ms |
5660 KiB |
| 00-sample-004.txt |
AC |
2 ms |
5824 KiB |
| 01-001.txt |
AC |
2 ms |
5884 KiB |
| 01-002.txt |
AC |
1 ms |
5644 KiB |
| 01-003.txt |
AC |
1 ms |
5832 KiB |
| 01-004.txt |
AC |
1 ms |
5680 KiB |
| 01-005.txt |
AC |
2 ms |
5904 KiB |
| 01-006.txt |
AC |
9 ms |
6268 KiB |
| 01-007.txt |
AC |
21 ms |
6708 KiB |
| 01-008.txt |
AC |
13 ms |
6532 KiB |
| 01-009.txt |
AC |
7 ms |
6100 KiB |
| 01-010.txt |
AC |
19 ms |
6728 KiB |
| 01-011.txt |
AC |
34 ms |
7632 KiB |
| 01-012.txt |
AC |
35 ms |
7500 KiB |
| 01-013.txt |
AC |
34 ms |
7772 KiB |
| 01-014.txt |
AC |
35 ms |
7504 KiB |
| 01-015.txt |
AC |
35 ms |
7720 KiB |
| 01-016.txt |
AC |
35 ms |
7784 KiB |
| 01-017.txt |
AC |
34 ms |
7592 KiB |
| 01-018.txt |
AC |
34 ms |
7656 KiB |
| 01-019.txt |
AC |
35 ms |
7776 KiB |
| 01-020.txt |
AC |
35 ms |
7616 KiB |
| 01-021.txt |
AC |
29 ms |
7588 KiB |
| 01-022.txt |
AC |
29 ms |
7596 KiB |
| 01-023.txt |
AC |
29 ms |
7784 KiB |
| 01-024.txt |
AC |
34 ms |
7620 KiB |
| 01-025.txt |
AC |
33 ms |
7612 KiB |
| 01-026.txt |
AC |
34 ms |
7784 KiB |
| 01-027.txt |
AC |
34 ms |
7596 KiB |
| 01-028.txt |
AC |
34 ms |
7616 KiB |