結果
問題 | No.868 ハイパー部分和問題 |
ユーザー | LayCurse |
提出日時 | 2019-08-21 06:06:27 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 844 ms / 7,000 ms |
コード長 | 8,479 bytes |
コンパイル時間 | 3,101 ms |
コンパイル使用メモリ | 218,320 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-10-07 16:18:34 |
合計ジャッジ時間 | 8,461 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 2 ms
5,248 KB |
testcase_02 | AC | 2 ms
5,248 KB |
testcase_03 | AC | 1 ms
5,248 KB |
testcase_04 | AC | 1 ms
5,248 KB |
testcase_05 | AC | 2 ms
5,248 KB |
testcase_06 | AC | 2 ms
5,248 KB |
testcase_07 | AC | 2 ms
5,248 KB |
testcase_08 | AC | 2 ms
5,248 KB |
testcase_09 | AC | 2 ms
5,248 KB |
testcase_10 | AC | 1 ms
5,248 KB |
testcase_11 | AC | 1 ms
5,248 KB |
testcase_12 | AC | 1 ms
5,248 KB |
testcase_13 | AC | 2 ms
5,248 KB |
testcase_14 | AC | 143 ms
5,248 KB |
testcase_15 | AC | 147 ms
5,248 KB |
testcase_16 | AC | 147 ms
5,248 KB |
testcase_17 | AC | 143 ms
5,248 KB |
testcase_18 | AC | 143 ms
5,248 KB |
testcase_19 | AC | 95 ms
5,248 KB |
testcase_20 | AC | 95 ms
5,248 KB |
testcase_21 | AC | 95 ms
5,248 KB |
testcase_22 | AC | 96 ms
5,248 KB |
testcase_23 | AC | 93 ms
5,248 KB |
testcase_24 | AC | 94 ms
5,248 KB |
testcase_25 | AC | 92 ms
5,248 KB |
testcase_26 | AC | 93 ms
5,248 KB |
testcase_27 | AC | 92 ms
5,248 KB |
testcase_28 | AC | 92 ms
5,248 KB |
testcase_29 | AC | 69 ms
5,248 KB |
testcase_30 | AC | 77 ms
5,248 KB |
testcase_31 | AC | 70 ms
5,248 KB |
testcase_32 | AC | 140 ms
5,248 KB |
testcase_33 | AC | 142 ms
5,248 KB |
testcase_34 | AC | 832 ms
5,248 KB |
testcase_35 | AC | 844 ms
5,248 KB |
testcase_36 | AC | 156 ms
5,248 KB |
testcase_37 | AC | 153 ms
5,248 KB |
testcase_38 | AC | 2 ms
5,248 KB |
testcase_39 | AC | 2 ms
5,248 KB |
ソースコード
#pragma GCC optimize ("Ofast") #include<bits/stdc++.h> using namespace std; #define MD 1000000007 struct Rand{ unsigned w, x, y, z; Rand(void){ x=123456789; y=362436069; z=521288629; w=(unsigned)time(NULL); } Rand(unsigned seed){ x=123456789; y=362436069; z=521288629; w=seed; } inline unsigned get(void){ unsigned t; t = (x^(x<<11)); x=y; y=z; z=w; w = (w^(w>>19))^(t^(t>>8)); return w; } inline double getUni(void){ return get()/4294967296.0; } inline int get(int a){ return (int)(a*getUni()); } inline int get(int a, int b){ return a+(int)((b-a+1)*getUni()); } inline long long get(long long a){ return(long long)(a*getUni()); } inline long long get(long long a, long long b){ return a+(long long)((b-a+1)*getUni()); } inline double get(double a, double b){ return a+(b-a)*getUni(); } inline int getExp(int a){ return(int)(exp(getUni()*log(a+1.0))-1.0); } inline int getExp(int a, int b){ return a+(int)(exp(getUni()*log((b-a+1)+1.0))-1.0); } } ; struct mint{ static unsigned R, RR, Rinv, W, md, mdninv; unsigned val; mint(){ } mint(int a){ val = mulR(a); } mint(unsigned a){ val = mulR(a); } mint(long long a){ val = mulR(a); } mint(unsigned long long a){ val = mulR(a); } int get_inv(long long a, int md){ long long e, s=md, t=a, u=1, v=0; while(s){ e=t/s; t-=e*s; u-=e*v; swap(t,s); swap(u,v); } if(u<0){ u+=md; } return u; } void setmod(unsigned m){ int i; unsigned t; W = 32; md = m; R = (1ULL << W) % md; RR = (unsigned long long)R*R % md; switch(m){ case 104857601: Rinv = 2560000; mdninv = 104857599; break; case 998244353: Rinv = 232013824; mdninv = 998244351; break; case 1000000007: Rinv = 518424770; mdninv = 2226617417U; break; case 1000000009: Rinv = 171601999; mdninv = 737024967; break; case 1004535809: Rinv = 234947584; mdninv = 1004535807; break; case 1007681537: Rinv = 236421376; mdninv = 1007681535; break; case 1012924417: Rinv = 238887936; mdninv = 1012924415; break; case 1045430273: Rinv = 254466304; mdninv = 1045430271; break; case 1051721729: Rinv = 257538304; mdninv = 1051721727; break; default: Rinv = get_inv(R, md); mdninv = 0; t = 0; for(i=0;i<((int)W);i++){ if(t%2==0){ t+=md; mdninv |= (1U<<i); } t /= 2; } } } unsigned mulR(unsigned a){ return (unsigned long long)a*R%md; } unsigned mulR(int a){ if(a < 0){ a = a%md+md; } return mulR((unsigned)a); } unsigned mulR(unsigned long long a){ return mulR((unsigned)(a%md)); } unsigned mulR(long long a){ a %= md; if(a < 0){ a += md; } return mulR((unsigned)a); } unsigned reduce(unsigned T){ unsigned m=T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned reduce(unsigned long long T){ unsigned m=(unsigned)T * mdninv, t=(unsigned)((T + (unsigned long long)m*md) >> W); if(t >= md){ t -= md; } return t; } unsigned get(){ return reduce(val); } mint &operator+=(mint a){ val += a.val; if(val >= md){ val -= md; } return *this; } mint &operator-=(mint a){ if(val < a.val){ val = val + md - a.val; } else{ val -= a.val; } return *this; } mint &operator*=(mint a){ val = reduce((unsigned long long)val*a.val); return *this; } mint &operator/=(mint a){ return *this *= a.inverse(); } mint operator+(mint a){ return mint(*this)+=a; } mint operator-(mint a){ return mint(*this)-=a; } mint operator*(mint a){ return mint(*this)*=a; } mint operator/(mint a){ return mint(*this)/=a; } mint operator+(int a){ return mint(*this)+=mint(a); } mint operator-(int a){ return mint(*this)-=mint(a); } mint operator*(int a){ return mint(*this)*=mint(a); } mint operator/(int a){ return mint(*this)/=mint(a); } mint operator+(long long a){ return mint(*this)+=mint(a); } mint operator-(long long a){ return mint(*this)-=mint(a); } mint operator*(long long a){ return mint(*this)*=mint(a); } mint operator/(long long a){ return mint(*this)/=mint(a); } mint operator-(void){ mint res; if(val){ res.val=md-val; } else{ res.val=0; } return res; } operator bool(void){ return val!=0; } operator int(void){ return get(); } operator long long(void){ return get(); } mint inverse(){ int a=val, b=md, t, u=1, v=0; mint res; while(b){ t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); } if(u < 0){ u += md; } res.val = (unsigned long long)u*RR % md; return res; } mint pw(unsigned long long b){ mint a(*this), res; res.val = R; while(b){ if(b&1){ res *= a; } b >>= 1; a *= a; } return res; } bool operator==(int a){ return mulR(a)==val; } bool operator!=(int a){ return mulR(a)!=val; } } ; mint operator+(int a, mint b){ return mint(a)+=b; } mint operator-(int a, mint b){ return mint(a)-=b; } mint operator*(int a, mint b){ return mint(a)*=b; } mint operator/(int a, mint b){ return mint(a)/=b; } mint operator+(long long a, mint b){ return mint(a)+=b; } mint operator-(long long a, mint b){ return mint(a)-=b; } mint operator*(long long a, mint b){ return mint(a)*=b; } mint operator/(long long a, mint b){ return mint(a)/=b; } inline void rd(int &x){ int k, m=0; x=0; for(;;){ k = getchar_unlocked(); if(k=='-'){ m=1; break; } if('0'<=k&&k<='9'){ x=k-'0'; break; } } for(;;){ k = getchar_unlocked(); if(k<'0'||k>'9'){ break; } x=x*10+k-'0'; } if(m){ x=-x; } } inline void wt_L(char a){ putchar_unlocked(a); } inline void wt_L(int x){ char f[10]; int m=0, s=0; if(x<0){ m=1; x=-x; } while(x){ f[s++]=x%10; x/=10; } if(!s){ f[s++]=0; } if(m){ putchar_unlocked('-'); } while(s--){ putchar_unlocked(f[s]+'0'); } } template<class T> inline int isPrime_L(T n){ T i; if(n<=1){ return 0; } if(n<=3){ return 1; } if(n%2==0){ return 0; } for(i=3;i*i<=n;i+=2){ if(n%i==0){ return 0; } } return 1; } unsigned mint::R, mint::RR, mint::Rinv, mint::W, mint::md, mint::mdninv; int N; int K; int A[15000]; int Q; int X; int V; mint dp[15001]; void go(int m){ int i; if(m==0){ return; } for(i=K;i>=m;i--){ dp[i] += dp[i-m]; } } void back(int m){ int i; if(m==0){ return; } for(i=(m);i<(K+1);i++){ dp[i] -= dp[i-m]; } } int main(){ Rand rnd; int Lj4PdHRW, Q5VJL1cS, i, j, k, m; { mint x; x.setmod(MD); } for(Lj4PdHRW=0;Lj4PdHRW<(100);Lj4PdHRW++){ m = rnd.get(900000000, 1010000000); } while(!isPrime_L(m)){ m++; } dp[0].setmod(m); rd(N); rd(K); { int KL2GvlyY; for(KL2GvlyY=0;KL2GvlyY<(N);KL2GvlyY++){ rd(A[KL2GvlyY]); } } rd(Q); dp[0] = 1; for(i=0;i<(N);i++){ go(A[i]); } for(Q5VJL1cS=0;Q5VJL1cS<(Q);Q5VJL1cS++){ rd(X);X += (-1); rd(V); back(A[X]); A[X] = V; go(A[X]); if((int)dp[K]){ wt_L(1); wt_L('\n'); } else{ wt_L(0); wt_L('\n'); } } return 0; } // cLay varsion 20190820-1 // --- original code --- // int N, K, A[15000], Q, X, V; // // mint dp[15001]; // // void go(int m){ // int i; // if(m==0) return; // for(i=K;i>=m;i--) dp[i] += dp[i-m]; // } // // void back(int m){ // int i; // if(m==0) return; // rep(i,m,K+1) dp[i] -= dp[i-m]; // } // // { // int i, j, k, m; // Rand rnd; // // rep(100) m = rnd.get(9d8, 1.01d9); // while(!isPrime(m)) m++; // dp[0].setmod(m); // // rd(N,K,A(N),Q); // // dp[0] = 1; // rep(i,N) go(A[i]); // // rep(Q){ // rd(X--, V); // back(A[X]); // A[X] = V; // go(A[X]); // if((int)dp[K]) wt(1); else wt(0); // } // }