답안 #947279

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
947279 2024-03-15T20:48:12 Z SuPythony Seesaw (JOI22_seesaw) C++17
0 / 100
1 ms 348 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);
    bool pos=true;
    for (int i=2; i<=n; i++) {
        if ((va[i]<=vb[i])==(va[1]<=vb[1])) 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;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 348 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -