QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#171315 | #7108. Couleur | Tjan# | WA | 1376ms | 29856kb | C++17 | 3.6kb | 2023-09-09 16:48:05 | 2023-09-09 16:48:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define For(i,a,b) for(int i=(a);i<=(b);i++)
#define Rof(i,a,b) for(int i=(a);i>=(b);i--)
#define ll long long
#define wln putchar('\n')
template<class T1,class T2> void chkmin(T1 &x,T2 y){if(y<x)x=y;}
template<class T1,class T2> void chkmax(T1 &x,T2 y){if(y>x)x=y;}
#define maxn 100005
int T;
int n;
struct node{
int val, lc, rc;
}t[maxn * 20];
int e = 0;
int a[maxn];
int rt[maxn];
ll ans = 0;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
set<piii> st;
multiset<int> as;
void init()
{
e = 0;
ans = 0;
st.clear();
as.clear();
}
int newnode()
{
e++;
t[e] = {0, 0, 0};
return e;
}
void make(int pre, int now, int v, int l, int r)
{
if(l == r) {
t[now].val = t[pre].val + 1;
return ;
}
int mid = (l + r) / 2;
if(v <= mid) {
t[now].rc = t[pre].rc;
t[now].lc = newnode();
ans += t[t[now].rc].val;
make(t[pre].lc, t[now].lc, v, l, mid);
}
else {
t[now].lc = t[pre].lc;
t[now].rc = newnode();
make(t[pre].rc, t[now].rc, v, mid + 1, r);
}
t[now].val = t[t[now].lc].val + t[t[now].rc].val;
}
int rnk(int pre, int now, int v, int l, int r)
{
if(l == r) return 0;
int mid = (l + r) / 2;
if(v <= mid) return rnk(t[pre].lc, t[now].lc, v, l, mid);
return t[t[now].lc].val - t[t[pre].lc].val + rnk(t[pre].rc, t[now].rc, v, mid + 1, r);
}
int bg(int pre, int now, int v, int l, int r)
{
if(l == r) return 0;
int mid = (l + r) / 2;
if(v <= mid) return t[t[now].rc].val - t[t[pre].rc].val + bg(t[pre].lc, t[now].lc, v, l, mid);
return bg(t[pre].rc, t[now].rc, v, mid + 1, r);
}
void Main()
{
init();
scanf("%d", &n);
For(i, 1, n) scanf("%d", &a[i]);
For(i, 1, n) {
rt[i] = newnode();
make(rt[i - 1], rt[i], a[i], 1, n);
}
int p;
as.insert(ans);
st.insert({{1, n}, ans});
For(i, 1, n) {
auto it = as.end();
it--;
ans = *it;
//as.erase(it);
printf("%lld ", ans);
scanf("%d", &p);
p ^= ans;
auto itt = st.lower_bound({{p, n + 1}, 0});
itt--;
int l = itt -> first.first, r = itt -> first.second;
ll tmp = itt ->second;
st.erase(itt);
it = as.find(tmp);
as.erase(it);
ll l0 = 0, r0 = 0, p0 = 0;
if(p - l <= r - p) {
For(i, l + 1, p - 1) {
l0 += bg(rt[l - 1], rt[i], a[i], 1, n);
}
For(i, l, p) {
r0 += rnk(rt[p], rt[r], a[i], 1, n);
}
p0 = bg(rt[l - 1], rt[p], a[p], 1, n);
r0 = tmp - l0 - p0 - r0;
}
else {
For(i, p + 1, r) {
r0 += bg(rt[p], rt[i], a[i], 1, n);
}
For(i, p, r) {
l0 += bg(rt[l - 1], rt[p - 1], a[i], 1, n);
}
p0 = rnk(rt[p], rt[r], a[p], 1, n);
l0 = tmp - r0 - p0 - l0;
}
if(p - 1 >= l)
st.insert({{l, p - 1}, l0}), as.insert(l0);
if(r >= p + 1)
st.insert({{p + 1, r}, r0}), as.insert(r0);
}
printf("\n");
}
int main()
{
scanf("%d", &T);
while(T--) Main();
return 0;
}
/*
3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10
1
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3868kb
input:
3 5 4 3 1 1 1 5 4 5 3 1 10 9 7 1 4 7 8 5 7 4 8 21 8 15 5 9 2 4 5 10 6 15 4 8 8 1 12 1 10 14 7 14 2 9 13 10 3 37 19 23 15 7 2 10 15 2 13 4 5 8 7 10
output:
7 0 0 0 0 20 11 7 2 0 0 0 0 0 0 42 31 21 14 14 4 1 1 1 0 0 0 0 0 0
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 1376ms
memory: 29856kb
input:
11116 10 10 5 10 3 6 4 8 5 9 8 31 27 24 11 12 3 0 2 3 1 10 8 2 7 2 8 10 1 10 9 10 6 5 2 13 2 1 0 1 3 1 10 7 10 7 6 1 3 10 6 7 9 21 18 10 1 6 5 4 8 9 10 10 2 10 4 8 8 5 7 2 6 7 20 10 9 1 15 0 4 2 9 7 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 10 1 2 3 4 5 6 7 8 9 10 6 3 5 2 7 10 9 1 4 8 10 1 10 1 3...
output:
21 18 16 12 10 6 4 1 1 0 12 12 10 10 4 4 4 2 1 0 20 16 9 5 3 3 3 0 0 0 22 14 8 8 5 5 2 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 19 12 7 4 4 2 2 1 0 0 20 18 8 3 1 1 0 0 0 0 45 21 21 10 3 3 3 0 0 0 17 11 8 2 1 1 1 0 0 0 13 4 1 0 0 0 0 0 0 0 29 27 22 15 9 7 4 3 1 0 26 16 9 2 1 1 1 1 1 ...
result:
wrong answer 11111th lines differ - expected: '2512961269 2512932299 25129263...6 46 35 31 23 17 10 8 8 4 1 0 0', found: '-1782006027 -1782034997 -17820... 46 35 31 23 17 10 8 8 4 1 0 0 '