QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#197678 | #6407. Classical A+B Problem | ucup-team870# | WA | 1ms | 11872kb | C++14 | 3.0kb | 2023-10-02 18:16:53 | 2023-10-02 18:16:53 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i,l,r) for(int i=l; i<=r; i++)
#define per(i,r,l) for(int i=r; i>=l; i--)
#define IOS {cin.tie(0);cout.tie(0);ios::sync_with_stdio(0);}
#define lc son[now][0]
#define rc son[now][1]
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int N = 1000020;
int son[N][2], wt[N], tot, root;
unsigned val[N], sum[N], add[N], sz[N], L[N], R[N];
int newNode(unsigned x, int l, int r) {
tot++;
// cout << tot <<' '<<l<<" "<<r<<"$$$$$$$$$$$$$\n";
R[tot] = r;
L[tot] = l;
sz[tot] = r-l+1;
val[tot] = x;
sum[tot] = x * (r - l + 1);
wt[tot] = rand();
return tot;
}
void up(int now) {
sz[now] = sz[lc] + sz[rc] + R[now] - L[now] + 1;
sum[now] = sum[lc] + sum[rc] + val[now] * (R[now] - L[now] + 1);
// cout << sum[now]<<"#"<<endl;
}
int merge(int x, int y) {
if (!x || !y) return x + y;
if (wt[x] < wt[y]) {
son[x][1] = merge(son[x][1], y);
up(x);
return x;
}
son[y][0] = merge(x, son[y][0]);
up(y);
return y;
}
void down(int now) {
if (add[now]) {
add[lc] += add[now];
add[rc] += add[now];
val[lc] += add[now];
val[rc] += add[now];
sum[lc] += add[now] * sz[lc];
sum[rc] += add[now] * sz[rc];
add[now] = 0;
}
}
void split(int now, int k, int &x, int &y) {
if (!now) {
x = y = 0;
return;
}
down(now);
if (L[now] <= k) x = now, split(rc, k, rc, y);
else y = now, split(lc, k, x, lc);
up(now);
}
void duan(int a) {
int x, y, z, t;
split(root, a, t, y);
int now = t;
// cout <<root<<"*****";
while (son[now][1]) now = son[now][1];
if (L[now] != a) {
// cout<<"%%"<<L[now]<<R[now]<<"---";
split(t, L[now]-1, x, z);
int ss = newNode(val[now], L[now], a-1);
int tt = newNode(val[now], a, R[now]);
root = merge(merge(x, merge(ss, tt)), y);
} else {
root = merge(t, y);
}
}
int main() {
srand(time(0));
int n, m; scanf("%d%d", &n, &m);
unsigned ksj = 0, mod = (1<<m);
root = newNode(0, 0, mod-1);
root = merge(newNode(0, -1, -1), root);
root = merge(root, newNode(0, mod, mod));
int x, y, z, t;
rep (i, 1, n) {
int p, q; scanf("%d%d", &p, &q);
p = (p + ksj % mod) % mod;
q = (q + ksj % mod) % mod;
int l = min(p, q), r = max(p, q);
cout <<l<<r<<"@";
// cout <<"("<<tot;
duan(l), duan(r+1);
// cout <<","<<tot<<")\n";
split(root, l-1, x, t);
split(t, r, y, z);
// cout << sz[y]<<"$";
unsigned u = i;
add[y] += u;
val[y] += u;
sum[y] += u * sz[y];
ksj += sum[y];
root = merge(x, merge(y, z));
cout <<ksj<<"$"<<endl;
// cout << sum[root]<<"#"<<endl;
}
cout << ksj % (1<<30) <<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 11872kb
input:
6 2 786 1332 89110 2333333 10000000000000000000000000001
output:
02@0$ 12@4$ 13@17$ 02@17$ 13@45$ 02@45$ 45
result:
wrong answer Token parameter [name=x] equals to "02@0$", doesn't correspond to pattern "[1-9]{1,1}" (test case 1)