QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#686939 | #6439. Cloud Retainer's Game | catch-up-from-behind | WA | 474ms | 5432kb | C++17 | 3.4kb | 2024-10-29 16:25:18 | 2024-10-29 16:25:19 |
Judging History
answer
// sis puella oier
#include <bits/stdc++.h>
using namespace std;
// #define int long long
typedef long long ll;
ll read(){
ll xx = 0, f = 1; char ch = getchar();
for (;!isdigit(ch); ch = getchar())f = (ch == '-' ? -1 : 1);
for (; isdigit(ch); ch = getchar())xx = (xx << 3) + (xx << 1) + ch - '0';
return xx * f;
}
const int N = 500100;
struct node{
int val, x, lt, ls, rs, pri;
}tr[N];
int cnt = 0;
int addp(int val, int x){tr[++cnt] = node{val, x, 0, 0, 0, rand()}; return cnt;}
void doit(int x, int va){if (x != 0)tr[x].x += va, tr[x].lt += va;}
void down(int x){if (tr[x].lt != 0)doit(tr[x].ls, tr[x].lt), doit(tr[x].rs, tr[x].lt), tr[x].lt = 0;}
void split(int u, int k, int &L, int &R){
if (u == 0){L = R = 0; return ;} down(u);
if (tr[u].x <= k)L = u, split(tr[u].rs, k, tr[u].rs, R);
else R = u, split(tr[u].ls, k, L, tr[u].ls);
}
int merge(int L, int R){
if (L == 0 || R == 0)return L + R; down(L), down(R);
if (tr[L].pri >= tr[R].pri){tr[L].rs = merge(tr[L].rs, R); return L;}
else {tr[R].ls = merge(L, tr[R].ls); return R;}
}
int ans;
void work(int x){
if (x == 0)return ;
ans = max(ans, tr[x].val); down(x);
work(tr[x].ls), work(tr[x].rs);
}
int rt;
int H;
void swich(int &lst, int tmp){
int L, R;
int len = tmp - lst; len %= (H + H);
int nl = H + H - len;
// cout<<lst<<" "<<tmp<<" "<<len<<" "<<nl<<endl;
split(rt, nl, L, R);
// cout<<L<<" "<<R<<endl;
doit(L, len), doit(R, -nl);
rt = merge(R, L);
lst = tmp;
}
void out(int x){
if (x == 0)return ; down(x);
out(tr[x].ls); cout<<tr[x].x<<":"<<tr[x].val<<" "; out(tr[x].rs);
}
vector <array<int, 2>> op;
void solve(){
int n; op.clear();
rt = cnt = 0;
H = read(), n = read();
for (int i = 1, x, y; i <= n; ++i)x = read(), y = read(),
op.push_back({x, y});
n = read();
for (int i = 1, x, y; i <= n; ++i)x = read(), y = read(),
op.push_back({x, -y});
sort(op.begin(), op.end());
int lst = 0, y, L, R, p, mx, L2, R2, p2; rt = addp(0, 0);
for (int i = 0, j; i < op.size(); ){
j = i + 1; while(j < op.size() && op[j][0] == op[i][0])++j;
swich(lst, op[i][0]);
// out(rt); cout<<endl;
while(i < j){
y = abs(op[i][1]);
if (op[i][1] < 0){
split(rt, y, L, R), split(L, y - 1, L, p);
if (p != 0)++tr[p].val; rt = merge(merge(L, p), R);
split(rt, H + H - y, L, R), split(L, H + H - y - 1, L, p);
if (p != 0)++tr[p].val; rt = merge(merge(L, p), R);
}
else {
mx = 0;
split(rt, y, L, R), split(L, y - 1, L, p);
if (p != 0)mx = max(mx, tr[p].val);
split(R, H + H - y, L2, R2), split(L2, H + H - y - 1, L2, p2);
if (p2 != 0)mx = max(mx, tr[p2].val);
if (p != 0)tr[p].val = max(tr[p].val, mx);
else p = addp(mx, y);
if (p2 != 0)tr[p2].val = max(tr[p2].val, mx);
else p2 = addp(mx, H + H - y);
rt = merge(merge(L, p), merge(merge(L2, p2), R2));
}
// cout<<i<<" ::\n";
// out(rt); cout<<endl;
++i;
}
}
ans = 0; work(rt);
printf("%d\n", ans);
}
signed main(){
srand(time(0));
int _ = read();
while(_--)solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3832kb
input:
2 4 3 1 1 2 2 6 2 4 3 1 3 3 5 1 7 3 3 1 4 2 3 1 1 6 2 9 1
output:
3 3
result:
ok 2 number(s): "3 3"
Test #2:
score: -100
Wrong Answer
time: 474ms
memory: 5432kb
input:
5503 10 19 2 4 2 8 8 3 8 4 8 7 2 7 2 6 1 5 3 2 6 4 2 1 4 5 2 5 7 1 4 7 5 7 2 2 8 6 8 1 12 5 1 4 8 5 2 6 1 3 6 1 1 1 7 7 2 5 6 6 8 1 2 3 5 10 5 9 5 10 7 6 6 5 7 1 3 9 6 8 8 8 6 4 2 9 5 4 4 2 10 9 2 3 2 1 7 1 4 3 14 4 6 6 1 2 1 7 6 2 3 4 4 5 3 6 5 1 4 3 4 3 2 6 2 8 6 8 2 6 6 5 2 5 1 3 1 2 3 7 4 5 5 3 ...
output:
2 1 2 1 3 3 3 3 4 6 2 2 1 1 2 2 2 3 3 2 1 0 2 1 2 3 3 3 3 3 1 3 1 4 5 2 3 1 0 2 3 4 2 3 3 3 2 1 0 3 2 3 2 2 4 1 2 1 3 2 3 3 3 1 2 2 2 3 2 4 2 1 1 3 2 3 0 1 3 4 5 2 2 1 1 3 1 3 0 1 3 1 3 3 2 2 1 3 4 3 3 4 4 2 3 4 2 4 3 4 2 1 0 1 3 1 3 1 3 2 1 3 5 1 4 2 2 0 2 3 1 3 3 2 4 2 2 1 3 3 2 1 1 3 1 2 3 1 4 3 ...
result:
wrong answer 6th numbers differ - expected: '2', found: '3'