Submission #947278

# Submission time Handle Problem Language Result Execution time Memory
947278 2024-03-15T20:47:24 Z SuPythony Bliskost (COI23_bliskost) C++17
0 / 100
0 ms 344 KB
#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);
    int c=va[1]<=vb[1];
    bool pos=true;
    for (int i=2; i<=n; i++) {
        if (va[i]<=vb[i]==c) continue;
        pos=false;
        break;
    }
    if (fa.query(n)-fb.query(n)==0&&pos) 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;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:55:18: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
   55 |         if (va[i]<=vb[i]==c) continue;
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -