QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#219038 | #7108. Couleur | euphria# | RE | 1ms | 7772kb | C++20 | 3.6kb | 2023-10-18 22:45:00 | 2023-10-18 22:45:01 |
Judging History
answer
//It's MyGO!!!
//All OK
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(0);cout << fixed << setprecision(6)
#define fi first
#define se second
#define INF 0x3f3f3f3f
#define LNF (1ll << 60)
#define ll long long
#define ull unsighed long long
#define int long long
// #define mod 998244353
#define mod 1000000007
using namespace std;
const int N = 1e5 + 10;
int n, m, a[N], p[N];
int root[N], tot;
map<int, int> mp;
multiset<int> s;
struct Node
{
int ls, rs;
int sum;
}tr[N << 4];
int newpoint(){
tot ++;
tr[tot] = {0, 0, 0};
return tot;
}
void modify(int a, int b, int l, int r, int idx){
// cout << l << ' ' << r << ' ' << idx << '\n';
tr[b] = tr[a];
if(l == r){
tr[b].sum ++;
return;
}
int mid = l + r >> 1;
if(idx <= mid) modify(tr[a].ls, tr[b].ls = newpoint(), l, mid, idx);
else modify(tr[a].rs, tr[b].rs = newpoint(), mid + 1, r, idx);
tr[b].sum = tr[tr[b].ls].sum + tr[tr[b].rs].sum;
}
int query(int u, int l, int r, int lx, int rx){
// cout << u << ' ' << l << ' ' << r << ' ' << lx << ' ' << rx << '\n';
if(lx > rx) return 0;
if(lx <= l && r <= rx) return tr[u].sum;
int mid = l + r >> 1;
ll res = 0;
if(lx <= mid) res += query(tr[u].ls, l, mid, lx, rx);
if(mid < rx) res += query(tr[u].rs, mid + 1, r, lx, rx);
return res;
}
void splite(int l, int r, int x){
// cout << l << ' ' << r << ' ' << mp[l] << endl;
ll res = mp[l];
s.erase(s.find(res));
ll sum = query(root[r - 1], 1, n, 1, a[x] - 1) - query(root[x], 1, n, 1, a[x] - 1) +
query(root[x - 1], 1, n, a[x] + 1, n) - query(root[l], 1, n, a[x] + 1, n);
if(x - l > r - x){
ll s1 = 0, s2 = 0;
for(int i = x + 1; i < r; i ++){
s1 += query(root[i - 1], 1, n, a[i] + 1, n) - query(root[x], 1, n, a[i] + 1, n);
s2 += query(root[x - 1], 1, n, a[i] + 1, n) - query(root[l], 1, n, a[i] + 1, n);
}
mp[l] = res - s1 - s2 - sum;
mp[x] = s1;
s.insert(res - s1 - s2 - sum);
s.insert(s1);
}
else{
ll s1 = 0, s2 = 0;
for(int i = l + 1; i < x; i ++){
s1 += query(root[i - 1], 1, n, a[i] + 1, n) - query(root[l], 1, n, a[i] + 1, n);
s2 += query(root[r - 1], 1, n, 1, a[i] - 1) - query(root[x], 1, n, 1, a[i] - 1);
}
mp[x] = res - s1 - s2 - sum;
mp[l] = s1;
s.insert(res - s1 - s2 - sum);
s.insert(s1);
}
}
void solve(){
cin >> n;
for(int i = 1; i <= n; i ++)
cin >> a[i];
for(int i = 1; i <= n; i ++){
modify(root[i - 1], root[i] = newpoint(), 1, n, a[i]);
}
ll sum = 0;
for(int i = 1; i <= n; i ++){
// cout << a[i] << ' ' << query(root[i - 1], 1, n, 1, a[i]) << '\n';
sum += query(root[i - 1], 1, n, a[i] + 1, n);
}
// cout << sum << endl;
mp[0] = sum;
mp[n + 1] = 0;
s.insert(sum), s.insert(0);
for(int i = 1; i <= n; i ++){
int x; cin >> x;
cout << sum << ' ';
x ^= sum;
auto idx = mp.lower_bound(x);
idx --;
// cout << idx->first << ' ' << next(idx)->first << '\n';
splite(idx->first, next(idx)->first, x);
auto id = s.end();
id --;
sum = *id;
}
tot = 0;
mp.clear();
s.clear();
cout << '\n';
}
signed main(){
ios;
// init();
int _ = 1;
cin >> _;
for(int __ = 1; __ <= _; __ ++){
// cout << "Case #" << __ << ": ";
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 7772kb
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
Runtime Error
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 ...