Submission #947275

#TimeUsernameProblemLanguageResultExecution timeMemory
947275SuPythonyBliskost (COI23_bliskost)C++17
0 / 100
0 ms348 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; class BIT { vector<int> bit; int size; public: BIT(int n, vector<int> vals) { bit.resize(n+1,0); size=n; for (int i=1; i<=n; i++) { update(i,vals[i]); } } void update(int pos, int val) { while (pos<=size) { bit[pos]+=val; pos+=pos&-pos; } } int query(int pos) { int ans=0; while (pos>0) { ans+=bit[pos]; pos-=pos&-pos; } return ans; } }; int main() { int n,q; cin>>n>>q; string a,b; cin>>a>>b; vector<int> va, vb; va.push_back(0); vb.push_back(0); for (int i=1; i<=n; i++) { if (n%2==i%2) { va.push_back(a[i-1]-'a'+1); vb.push_back(b[i-1]-'a'+1); } else { va.push_back(-(a[i-1]-'a'+1)); vb.push_back(-(b[i-1]-'a'+1)); } } BIT fa=BIT(n,va); BIT fb=BIT(n,vb); if (fa.query(n)-fb.query(n)==0) cout<<"da\n"; else cout<<"ne\n"; while (q--) { int p; char a; cin>>p>>a; if (n%2==p%2) fa.update(p,(a-'a'+1)-va[p]); else fa.update(p,-(a-'a'+1)-va[p]); va[p]=a-'a'+1; if (fa.query(n)-fb.query(n)==0) cout<<"da\n"; else cout<<"ne\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...