QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85050 | #5233. Wielki Zderzacz Termionów [A] | anhduc2701 | 0 | 67ms | 26976kb | C++23 | 4.6kb | 2023-03-06 22:13:57 | 2023-03-06 22:14:22 |
Judging History
answer
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) ll(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "WZT"
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;
int inv2;
string s;
int inv[maxn];
int invfact[maxn];
int fact[maxn];
int binpow(int a,int b){
int res=1;
while(b>0){
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
int calc(int z,int t){
int d=binpow(2,z);
if(z%2==1){
d-=2;
}
else{
d-=1;
}
if(d<0)d+=mod;
if(z%6==0){
if(t==1 || t==2){
return d*inv[3]%mod;
}
else{
return (d*inv[3]+1)%mod;
}
}
else if(z%6==1){
if(t==0 || t==1){
return (d*inv[3]+1)%mod;
}
else{
return d*inv[3]%mod;
}
}
else if(z%6==2){
if(t==0 || t==2){
return d*inv[3]%mod;
}
else{
return (d*inv[3]+1)%mod;
}
}
else if(z%6==3){
if(t==1 || t==2){
return (d*inv[3]+1)%mod;
}
else{
return d*inv[3]%mod;
}
}
else if(z%6==4){
if(t==0 || t==1){
return d*inv[3]%mod;
}
else{
return (d*inv[3]+1)%mod;
}
}
else{// z%6==5
if(t==0 || t==2){
return (d*inv[3]+1)%mod;
}
else{
return d*inv[3]%mod;
}
}
}
int N,C,Z;
int ok=0;
int Z1;
int Z2;
int C1;
int C2;
int so=0;
int calc(){
int q=(((N%3+(Z-C)%3)+6))%3;
if(q==1){
q=2;
}
else if(q==2){
q=1;
}
int ans=binpow(2,N)-calc(N,q);
if((Z1==n/2+1 && C2==n/2 ) && n%2==1){
ans--;
}
if(( C1==n/2 && Z2==n/2+1) && n%2==1){
ans--;
}
return (ans%mod+mod)%mod;
}
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
// freopen(task".inp" , "r" , stdin);
// freopen(task".out" , "w" , stdout);
cin>>n>>m;
cin>>s;
s=' '+s;
inv2=binpow(2,mod-2);
inv[1] =invfact[1]=fact[1]=inv[0]=invfact[0]=fact[0]= 1;
for(int i = 2; i < maxn; ++i){
inv[i] = mod - (mod/i) * inv[mod%i] % mod;
fact[i]= fact[i-1]*i%mod;
invfact[i]=invfact[i-1]*inv[i]%mod;
}
for(int i=1;i<=n;i++){
if(s[i]=='C'){
if(i%2==1){
C1++;
}
else{
C2++;
}
C++;
}
if(s[i]=='Z'){
if(i%2==1){
Z1++;
}
else{
Z2++;
}
Z++;
}
if(s[i]=='N'){
if(i%2==1){
C1++;
}
else{
C2++;
}
if(i%2==1){
Z1++;
}
else{
Z2++;
}
N++;
}
}
for(int i=2;i<=n;i++){
if(s[i]=='C' && s[i-1]=='C'){
so++;
}
if(s[i]=='Z' && s[i-1]=='Z'){
so++;
}
}
// cout<<calc()<<"\n";
for(int i=1;i<=m;i++){
int k;
char c;
cin>>k>>c;
if(s[k]=='C'){
if(k%2==1){
C1--;
}
else{
C2--;
}
C--;
}
if(s[k]=='Z'){
if(k%2==1){
Z1--;
}
else{
Z2--;
}
Z--;
}
if(s[k]=='N'){
if(k%2==1){
C1--;
}
else{
C2--;
}
if(k%2==1){
Z1--;
}
else{
Z2--;
}
N--;
}
if(k>1&& s[k]==s[k-1] && s[k]!='N'){
so--;
}
if(s[k]==s[k+1] && s[k]!='N' && k<n){
so--;
}
s[k]=c;
if(k>1&& s[k]==s[k-1] && s[k]!='N'){
so++;
}
if(s[k]==s[k+1] && s[k]!='N' && k<n){
so++;
}
if(s[k]=='C'){
if(k%2==1){
C1++;
}
else{
C2++;
}
C++;
}
if(s[k]=='Z'){
if(k%2==1){
Z1++;
}
else{
Z2++;
}
Z++;
}
if(s[k]=='N'){
if(k%2==1){
C1++;
}
else{
C2++;
}
if(k%2==1){
Z1++;
}
else{
Z2++;
}
N++;
}
cout<<calc()<<"\n";
}
return 0;
}
/*
1 1 1 0
2 1 2 1
3 2 3 3
4 5 5 6
5 11 10 11
6 22 21 21
7 43 43 42
8 85 86 85
9 170 171 171
10 341 341 342
11 683 682 683
12 1366 1365 1365
//
// 2^10 /3
// 2^9 * 2/3
// 2^
*/
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 16ms
memory: 26880kb
input:
20 20 CZZCZCCZNCZNZNNCCCZN 10 Z 16 Z 2 C 2 C 2 Z 3 Z 4 C 9 C 6 N 13 N 12 C 8 Z 18 Z 12 C 8 C 5 Z 10 Z 12 Z 9 Z 6 Z
output:
21 22 21 21 22 22 22 11 22 43 21 21 22 22 21 21 21 22 21 10
result:
wrong answer 2nd lines differ - expected: '21', found: '22'
Subtask #2:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 34ms
memory: 26760kb
input:
100 100 ZCZCCCZZNNZNNCCZNNNZZNCCZNNNZNNCNNZCCCZZZNNCNZCCZNNNZNZNNCZCNNZCZZCNCNNZCZCNNZCZCNCZNNCZZNCCNNNZZCZC 8 C 18 C 53 N 52 N 93 C 48 C 67 C 18 Z 57 Z 31 N 94 Z 90 Z 35 C 58 C 20 Z 12 C 87 N 5 C 71 C 21 Z 72 C 38 C 7 N 15 Z 100 Z 58 Z 77 N 87 C 37 Z 26 Z 64 Z 83 N 5 Z 82 C 71 C 37 Z 62 Z 36 N 28 N...
output:
251936681 625968344 251936682 251936682 625968345 625968345 625968345 625968344 812984175 812984175 906492091 453246046 453246045 453246045 453246045 726623026 453246045 453246045 726623026 726623026 726623027 726623027 453246046 453246046 453246045 453246046 453246046 726623026 726623027 863311517 ...
result:
wrong answer 1st lines differ - expected: '251936682', found: '251936681'
Subtask #3:
score: 0
Wrong Answer
Test #27:
score: 0
Wrong Answer
time: 31ms
memory: 26904kb
input:
10000 5000 NCZNZCCZCNCZCNCZZCCZCNZNZZNNCCNCZCNZCZCNZCNNZZNZZZNZCCZZZCCNCZNZCCNZCZZCNCZZNNNZCCCZNNZNZCCZNNCNCCCNZNNZCNCCCCZZZNNZNZNCCZCNNZNCCCNNZCNCNNZNCNCZNNCCZCCZNZCNZNCNNNZZNNNCNZNCNNCZCNNZZCCNCZCNNNNZCCNZCCCZZNZZCCZNNNZNNCZZNZZCNCZNNCCNZZCZNNNNCCZCCZCCZCCCZNNCCZZCCZZNCNCCCZNCCCZCZNNNCNNNCNZCCZNZZ...
output:
516850681 33701354 516850681 516850681 516850681 33701354 33701354 33701353 67402707 134805415 269610830 269610830 134805415 269610830 269610830 539221659 269610829 269610829 269610829 269610829 269610830 134805415 67402708 33701354 516850680 758425343 758425343 758425344 758425344 758425343 8792126...
result:
wrong answer 2nd lines differ - expected: '516850681', found: '33701354'
Subtask #4:
score: 0
Wrong Answer
Test #38:
score: 0
Wrong Answer
time: 25ms
memory: 26900kb
input:
30000 20000 ZZNNZNNZNNCZNNCCNZCCZZZZZZCZNNCCZCCCZNNNZCZNCCCZCCCNCZZNZCCNCZNNZCNZZZCZCNNCNNZCCNNCCCCCZZNCNZZZCZCCNZNZZNNNCCCZNCCZNNZZCNCCNNNZZZZZNCNNZCZNCZNCCZCZZCNCZNNNCCNZCCCCCCNZNNCZZNCNZNNCZCNCZNCZZNZZNNCZCZCNZZCNNNNZNNZZZNZZNNNNNZCZCNNZZNCZCZCCNCCZZNCCCZZNZZCNNCNZZNNZNCCCZZNCCZCCNZCNCCZCCNNNNCZC...
output:
255456260 255456260 255456260 510912519 255456259 255456259 255456259 627728133 627728133 627728133 627728133 627728134 255456260 627728133 627728133 627728133 627728133 255456259 510912519 510912519 510912520 510912520 21825032 21825032 510912519 510912519 510912519 510912519 510912520 21825032 218...
result:
wrong answer 1st lines differ - expected: '627728134', found: '255456260'
Subtask #5:
score: 0
Wrong Answer
Test #50:
score: 0
Wrong Answer
time: 50ms
memory: 26932kb
input:
100000 50000 NNCZNCNCCZCZNCZZNNNNNZCNZCCCZCNCNZNCNZCNCCZZCZZNCZNZZNZCCCCNZNZNNNNNZNNCZNCZCNNZNCCNNZCNZNCNNZNZZCZNNCCCNCNNZCNCNNNNCZNNZNZCZNZZCCZNCCNZCNZZCNNZCNCNZNZNNZZCZZCCCCNCZZNZZCZCZNCNZZZCNNZNZCCZCNCZZNNCCNZNZNNCZCNCCCCNCNZZZZNNNCNZNCNCNCNCCZNCZNCNNZNCCNNNCNZZCZZCNZNZNCNCCZNNNCZCZCCCZCNCNZNCNZC...
output:
760867136 760867136 760867137 380433569 380433568 380433568 690216788 845108397 845108397 845108397 690216787 380433568 380433568 380433569 380433569 380433569 380433569 380433568 690216787 690216787 845108397 845108398 422554199 211277099 422554199 422554198 422554198 845108397 845108397 690216788 ...
result:
wrong answer 3rd lines differ - expected: '760867136', found: '760867137'
Subtask #6:
score: 0
Wrong Answer
Test #62:
score: 0
Wrong Answer
time: 67ms
memory: 26936kb
input:
200000 100000 ZNCCNZCNCZZZZZZNNNNCNZCCCNNNCCZNCZCCZZNZZCZCZCCCNZCNNNNNCNNCZCZNCCCZZNNZNZZZNCZNNZCNZCCNCZCCZNNZCNCCNZNCNNNNZZNNNZCCCZZNNZCNCNNCZNZZNNZZZCCCCCCNNNNNNCNZCCNCNZCZZNCNCNCCNZCZCCZNNNNZZZNCCCCNNNCNZCCNCCZCZCNCCNCNCZNNNCNZZNNZCZZZNZCZNNNZNZZNNCCCCCCZNCNNNZCNZZCZZNCCZNCNCCCNCCZCNZNZCZNZZCCNCZ...
output:
717427644 717427644 434855281 434855282 434855282 717427645 858713826 717427645 717427645 717427645 858713826 858713826 929356916 858713826 858713826 858713826 858713826 717427644 434855281 717427644 717427645 717427644 717427644 717427644 717427644 717427644 717427645 717427645 858713826 858713826 ...
result:
wrong answer 1st lines differ - expected: '717427645', found: '717427644'
Subtask #7:
score: 0
Wrong Answer
Test #75:
score: 0
Wrong Answer
time: 53ms
memory: 26912kb
input:
200000 100000 CCNNCZCNZCCCNCZZNZCCNCNCNNZCZZZCCZCCCCCNCZZNNZNCZNCZZNNCCNZZZZZNNNNZNNCZCNZCZNCNCZZZCNZNZNNCZNNNCCCCNNCZCCNNCZZCNZCNCCZZNZNNCNCCCNNZNNZZNZZCCNNCCZNZCNCNNZNCNNCNZZNZZNNZNNCCNCCNNZCCNZNCNZNCZNCNCNZCCZNCZNNZNNNZNZCCZNCZCZNZZNZCZZZCNCNZZZZZNNZNZZCCNNZNCNNNZNNNNZCNCCCCCCCNZCNCCZZCNNCNZCNZNC...
output:
464653872 929307745 929307745 929307745 464653873 929307745 929307744 929307745 858615483 858615483 717230958 717230957 717230957 434461908 717230957 434461908 717230958 434461908 434461909 434461909 434461909 717230958 434461908 717230958 717230957 434461908 434461908 434461908 717230957 717230957 ...
result:
wrong answer 1st lines differ - expected: '732326940', found: '464653872'
Subtask #8:
score: 0
Wrong Answer
Test #85:
score: 0
Wrong Answer
time: 54ms
memory: 26912kb
input:
200000 100000 ZZCCCZZCCZNZCZCZNCZCCZCNNNCZZZCNCZCCZCCZNZCCCNNCZZZNCNNCZZNCNCNNCCCZNCNZZCZCNCNCNCZCZCZNNNCNCCCCZNZNZNCCNCCCCNCCZZZNNZCCCCCNZNNZNCCCCZZZZCCNNZZNCNCZNCNCNNNZNZNZNCCNCNZCZCCCNNCCNNZNCNZCCZNZCZCCCZNZCNNCNNZZCCNZNZCZNZCNCCZZNZNCNCZCNNCCCNZNNNCZNNZCZZZCCZCNNZZNZNZCZCCCNNZCZCCCNNZZCZZZNNNZCC...
output:
516190438 758095223 758095223 758095223 379047611 379047611 379047611 379047611 189523806 189523805 189523805 379047611 758095222 758095223 379047612 379047612 379047611 189523806 189523805 189523805 594761906 594761906 797380957 797380957 398690478 797380956 398690478 797380956 797380956 797380956 ...
result:
wrong answer 2nd lines differ - expected: '516190438', found: '758095223'
Subtask #9:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 58ms
memory: 26976kb
input:
200000 100000 ZNCZCCCNNCCNCNCZCCZZCNNNNCZCCCZNNCNZNCNCNCZNCZNZNNZNNCCNZZCZZNZZCCNNNZCNNZCZCNCNZNZZNCZNZZNZZNZZZCNCNZNZCNNNCZZNCNZCZNCNNZZCZCCZZZZCZNNNCCCZCNNCNCNCNNCNNCCZNCZZCZZZZCCCZNCCCNCCZCNCCNNZCNNNCCZNCZCZNZCCZNNNZCCCZZZCZCCCZNZCCNNNNZNNCZNCNZNZNCNCCZNCZNZZCZNZNNCCNCNZNZZNCNZCCCNCZZNNNZNNNNZZNC...
output:
423710609 711855308 855927658 855927658 927963832 927963832 927963832 927963832 855927658 855927658 855927658 855927658 927963832 963981920 927963833 963981920 981990963 981990963 981990963 981990963 490995481 490995482 745497744 745497744 872748875 872748876 936374441 872748876 745497745 490995482 ...
result:
wrong answer 2nd lines differ - expected: '423710609', found: '711855308'
Subtask #10:
score: 0
Wrong Answer
Test #103:
score: 0
Wrong Answer
time: 60ms
memory: 26968kb
input:
200000 100000 CZNCNZZNNNZZNCCZNZCCNNNCZNCNZCCNNCNCCNNZCNZCNCCCCZNZNZNCCNNNNCCNCNZZNZNCZNZZCZNCCNZZCNZNZZCNNNNCZNCCZCZCCCZNNCZZNCZCZNCZNZZNZNCZCZCNNCZCZCCZNZCCNNCCCCZCCNNCNZNCCCNZZZZZZCCZZNCNCZNZZNCZCCZCNZNZZNNNCCCCNZCCZCNZZCNNCCNZZCZZCZZZZZNNZCNCZZZCCCCZCNZZZZNZZZZCCCZZCCNCZNCCZZCNNNCCNZZZCNCZNZCZNC...
output:
83887589 167775179 335550359 335550359 167775179 83887590 83887590 541943798 541943799 770971903 770971903 770971903 770971903 385485951 192742975 596371491 596371491 596371491 596371491 596371492 596371492 596371491 596371491 596371491 596371491 596371491 298185746 298185746 298185746 596371491 192...
result:
wrong answer 2nd lines differ - expected: '83887589', found: '167775179'