QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#472558#6409. Classical Data Structure Problemlllei#RE 0ms0kbC++203.2kb2024-07-11 17:09:202024-07-11 17:09:20

Judging History

你现在查看的是最新测评结果

  • [2024-07-11 17:09:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-07-11 17:09:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const long long M = 1ll << 30;
int n, m, len;
struct TREE {
    int x;
    long long t1, t2;
    long long ct1, ct2;
    int ls, rs,fa;
} tree[1000010];
int siz = 0, rt = 0;
long long x = 0;
void updata(int x){
    int ls=tree[x].ls,rs=tree[x].rs;
    tree[x].ct1=(tree[ls].ct1+tree[rs].ct1+tree[x].t1)%M;
    tree[x].ct2=(tree[ls].ct2+tree[rs].ct2+tree[x].t2)%M;
}
void rorate(int x){
    int fa=tree[x].fa;
    int ll=tree[fa].ls,rr=tree[fa].rs,rs=tree[x].rs,ls=tree[x].ls;
    int pa=tree[fa].fa;
    if(pa)
    {
    tree[x].fa=pa;
    if(fa==tree[pa].ls) tree[pa].ls=x;
    else tree[pa].rs=x;
    }
    if(x==ll){
       tree[rs].fa=fa;tree[fa].fa=x;tree[x].rs=fa;tree[fa].ls=rs;
       updata(fa);updata(x);
    }
    else
    {
        tree[ls].fa=fa;tree[fa].fa=x;tree[x].ls=fa;tree[fa].rs=ls;
        updata(fa); updata(x);
    }
    if(fa==rt) rt=x;
}
void sp(int x){
    while(x!=rt) rorate(x);
}
void insert(TREE tmp) {
    if (!siz) {
        siz = 1;
        tree[1] = tmp;
        rt = 1;
        return;
    }
    int now = rt, fa = 0;
    while (now) {
        tree[now].ct1 = (tree[now].ct1+tmp.t1)%M;
        tree[now].ct2 = (tree[now].ct2+tmp.t2)%M;
        if (tmp.x == tree[now].x) {
            tree[now].t1 = (tree[now].t1+tmp.t1)%M;
            tree[now].t2 = (tree[now].t2+tmp.t2)%M;
            return;
        }
        fa = now;
        if (tmp.x > tree[now].x) {
            now = tree[now].rs;
        } else
            now = tree[now].ls;
    }
    tmp.ct1 = tmp.t1;
    tmp.ct2 = tmp.t2;
    siz++;
    tree[siz] = tmp;
    if (tmp.x > tree[fa].x)
        tree[fa].rs = siz;
    else
        tree[fa].ls = siz;
    tree[siz].fa=fa;
    sp(siz);
    return;
}
long long tot1, tot2;
void find(int x) {
    tot1 = tot2 = 0;
    if (!siz) {
        tot1 = tot2 = 0;
        return;
    }
    int now = rt;
    while (now) {
        int ls = tree[now].ls, rs = tree[now].rs;
        if (x == tree[now].x) {
            tot1 = (tot1 + tree[ls].ct1 + tree[now].t1) % M;
            tot2 = (tot2 + tree[ls].ct2 + tree[now].t2) % M;
            return;
        }
        if (x > tree[now].x) {
            tot1 = (tot1 + tree[ls].ct1 + tree[now].t1) % M;
            tot2 = (tot2 + tree[ls].ct2 + tree[now].t2) % M;
            now = rs;
        } else {
            now = ls;
        }
    }
    return;
}
int main() {
    cin >> n >> m;
    len = 1 << m;
    for (int i = 1; i <= n; i++) {
        long long p, q;
        cin >> p >> q;
        p = (p + x) % len;
        q = (q + x) % len;
        if (p > q)
            swap(p, q);

        TREE tmp;
        tmp.ls = tmp.rs = 0;
        tmp.x = p;
        tmp.t1 = (-((p - 1) * i%M)+M)%M;
        tmp.t2 = i;
        insert(tmp);
        tmp.x = q;
        tmp.t1 = (q)*i%M;
        tmp.t2 = (-i+M)%M;
        insert(tmp);
        long long ans = 0;
        find(q);
        ans = (ans + tot1 + tot2 * q) % M;
        find(p - 1);
        ans = (ans - (tot1 + tot2 * (p - 1)) % M + M) % M;
        x = (x + ans) % M;
        // cout<<ans<<endl;
    }
    cout << x;
    return 0;
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

5 2
2 1
1 3
3 2
1 0
0 2

output:


result: