QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#158574 | #7108. Couleur | ucup-team1453# | AC ✓ | 2590ms | 38792kb | C++14 | 2.2kb | 2023-09-02 16:42:59 | 2023-09-02 16:42:59 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); i++)
#define R(i, j, k) for(int i = (j); i >= (k); i--)
#define sz(a) ((int) a.size())
#define vi vector<int>
#define ll long long
#define me(f, x) memset(f, x, sizeof(f))
#define ull unsigned long long
using namespace std;
const int N = 2e5 + 7, M = N * 20;
int n, a[N];
int sum[M], ch[M][2], tot;
void add(int &x, int L, int R, int p) {
++tot, ch[tot][0] = ch[x][0], ch[tot][1] = ch[x][1], sum[tot] = sum[x] + 1, x = tot;
if(L == R) return ;
int mid = (L + R) >> 1;
p <= mid ? add(ch[x][0], L, mid, p) : add(ch[x][1], mid + 1, R, p);
}
int query(int x, int L, int R, int l, int r) {
if(l <= L && R <= r) return sum[x];
int mid = (L + R) >> 1, ret = 0;
if(l <= mid) ret += query(ch[x][0], L, mid, l, r);
if(r > mid) ret += query(ch[x][1], mid + 1, R, l, r);
return ret;
}
int hd[N];
ll fen[N];
inline ll get(int l, int r) {
ll ans = 0;
L(i, l + 1, r)
ans +=
query(hd[i - 1], 0, n + 1, a[i] + 1, n + 1) -
query(hd[l - 1], 0, n + 1, a[i] + 1, n + 1);
return ans;
}
void Main() {
cin >> n;
L(i, 1, n) {
cin >> a[i], hd[i] = hd[i - 1], add(hd[i], 0, n + 1, a[i]);
}
set < int > st;
st.insert(0), st.insert(n + 1);
multiset < ll > ans;
ans.insert(get(1, n));
fen[1] = get(1, n);
L(i, 1, n) {
ll lst = *--ans.end();
cout << lst << " \n"[i == n];
ll u;
cin >> u, u ^= lst;
auto p = st.lower_bound(u);
int r = *p - 1;
int l = *--p + 1;
st.insert(u);
ans.erase(ans.lower_bound(fen[l]));
ll cur = fen[l];
if(u - l > r - u) {
R(i, r, u) {
cur -=
query(hd[i - 1], 0, n + 1, a[i] + 1, n + 1) -
query(hd[l - 1], 0, n + 1, a[i] + 1, n + 1);
}
fen[l] = cur;
fen[u + 1] = get(u + 1, r);
} else {
L(i, l, u) {
cur -=
query(hd[r], 0, n + 1, 0, a[i] - 1) -
query(hd[i], 0, n + 1, 0, a[i] - 1);
}
fen[l] = get(l, u - 1);
fen[u + 1] = cur;
}
ans.insert(fen[l]);
ans.insert(fen[u + 1]);
}
L(i, 1, tot) ch[i][0] = ch[i][1] = 0, sum[i] = 0;
tot = 0;
}
int main() {
ios :: sync_with_stdio (false);
cin.tie (0); cout.tie (0);
int t; cin >> t;
while(t--) Main();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3660kb
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: 0
Accepted
time: 2590ms
memory: 38792kb
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 0 0 0 0 0 0 ...
result:
ok 11116 lines
Extra Test:
score: 0
Extra Test Passed