QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#473193 | #6409. Classical Data Structure Problem | UESTC_Snow_Halation | WA | 7ms | 81828kb | C++14 | 4.0kb | 2024-07-11 22:58:21 | 2024-07-11 22:58:21 |
Judging History
answer
#include <iostream>
#include <algorithm>
#include <cstdlib>
using namespace std;
const int N = 2e6 + 7;
unsigned int Mod;
struct ModInt
{
unsigned int val;
ModInt() : val(0) {}
ModInt(int x) : val(x) {}
operator bool() const { return val != 0; }
ModInt operator+(const ModInt &X) const
{
ModInt tmp(val + X.val);
if (tmp.val >= Mod)
tmp.val -= Mod;
return tmp;
}
ModInt operator-(const ModInt &X) const
{
ModInt tmp(val - X.val);
if (tmp.val < 0)
tmp.val += Mod;
return tmp;
}
ModInt operator*(const ModInt &X) const
{
return ModInt(1ull * val * X.val % Mod);
}
const ModInt &operator+=(const ModInt &X)
{
val += X.val;
if (val >= Mod)
val -= Mod;
return (*this);
}
bool operator<(const ModInt &X) const
{
return val < X.val;
}
explicit operator int() const
{
return val;
}
};
istream &operator>>(istream &os, ModInt &X)
{
return os >> X.val;
}
ostream &operator<<(ostream &os, ModInt &X)
{
return os << X.val;
}
struct Node
{
ModInt Sum, val, tag;
int ls, rs, key;
int l, r, L, R;
} t[N];
int NewNode(int l, int r, ModInt val)
{
static int cnt = 0;
t[++cnt] = (Node){0, val, 0, 0, 0, rand(), l, r, l, r};
t[cnt].Sum = ModInt(r - l + 1) * t[cnt].val;
return cnt;
}
void update(int id)
{
t[id].L = t[id].ls ? t[t[id].ls].L : t[id].l;
t[id].R = t[id].rs ? t[t[id].rs].R : t[id].r;
t[id].Sum = t[t[id].ls].Sum + t[t[id].rs].Sum + t[id].val * ModInt(t[id].r - t[id].l + 1);
}
void add(int id, ModInt val)
{
t[id].val += val;
t[id].Sum += val * ModInt(t[id].R - t[id].L + 1);
t[id].tag += val;
}
void pd(int id)
{
if (!t[id].tag)
return;
if (t[id].ls)
add(t[id].ls, t[id].tag);
if (t[id].rs)
add(t[id].rs, t[id].tag);
t[id].tag = 0;
}
int merge(int x, int y)
{
if (!x || !y)
return x | y;
if (t[x].key <= t[y].key)
{
pd(x);
t[x].rs = merge(t[x].rs, y);
return update(x), x;
}
else
{
pd(y);
t[y].ls = merge(x, t[y].ls);
return update(y), y;
}
}
void split(int id, int k, bool op, int &x, int &y)
{
if (!id)
x = y = 0;
else
{
pd(id);
if ((!op && t[id].l <= k) || (op && t[id].r <= k))
x = id, split(t[x].rs, k, op, t[x].rs, y);
else
y = id, split(t[y].ls, k, op, x, t[y].ls);
update(id);
}
}
int n, m, rt;
void Split(int l, int r, int &x, int &y, int &z)
{
x = y = z = 0;
split(rt, l - 1, 0, x, y);
split(y, r, 1, y, z);
int now = x;
while (t[now].rs)
now = t[now].rs;
if (now && t[now].r > r)
{
y = NewNode(l, r, t[now].val);
z = merge(NewNode(r + 1, t[now].r, t[now].val), z);
t[now].r = l - 1;
update(now);
}
else
{
if (now && t[now].r >= l)
{
y = merge(NewNode(l, t[now].r, t[now].val), y);
t[now].r = l - 1;
update(now);
}
now = z;
while (t[now].ls)
now = t[now].ls;
if (now && t[now].l <= r)
{
y = merge(y, NewNode(t[now].l, r, t[now].val));
t[now].l = r + 1;
update(now);
}
}
}
int main()
{
ios::sync_with_stdio(false);
srand(114514);
cin >> n >> m;
m = 1 << m;
Mod = 1 << 30;
rt = NewNode(0, m - 1, 0);
int p, q = 0;
ModInt X = 0;
int x, y, z;
for (int i = 1; i <= n; i++)
{
cin >> p >> q;
p += int(X), q += int(X);
p %= m, q %= m;
if (p > q)
swap(p, q);
Split(p, q, x, y, z);
add(y, i);
X += t[y].Sum;
rt = merge(merge(x, y), z);
}
cout << X;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 81732kb
input:
5 2 2 1 1 3 3 2 1 0 0 2
output:
87
result:
ok 1 number(s): "87"
Test #2:
score: 0
Accepted
time: 7ms
memory: 81744kb
input:
1 1 1 1
output:
1
result:
ok 1 number(s): "1"
Test #3:
score: 0
Accepted
time: 4ms
memory: 81764kb
input:
1 2 3 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 7ms
memory: 81692kb
input:
1 5 31 15
output:
17
result:
ok 1 number(s): "17"
Test #5:
score: 0
Accepted
time: 3ms
memory: 81744kb
input:
1 20 366738 218765
output:
147974
result:
ok 1 number(s): "147974"
Test #6:
score: 0
Accepted
time: 7ms
memory: 81732kb
input:
1 30 86669484 41969116
output:
44700369
result:
ok 1 number(s): "44700369"
Test #7:
score: 0
Accepted
time: 0ms
memory: 81828kb
input:
10 5 20 31 2 2 14 18 13 25 26 4 22 9 15 9 19 16 15 27 9 20
output:
1414
result:
ok 1 number(s): "1414"
Test #8:
score: -100
Wrong Answer
time: 0ms
memory: 81760kb
input:
100 10 245 987 817 813 743 560 548 504 116 479 223 199 775 998 126 542 791 823 96 318 69 349 0 584 245 601 119 513 93 820 115 307 838 978 249 767 433 287 240 8 22 683 169 720 395 592 903 866 919 652 510 563 858 345 938 250 550 239 981 7 784 926 212 644 272 365 490 871 470 987 571 53 65 593 515 370 1...
output:
21053720
result:
wrong answer 1st numbers differ - expected: '20383734', found: '21053720'