QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#357179 | #7108. Couleur | arnold518 | AC ✓ | 1562ms | 20468kb | C++17 | 2.3kb | 2024-03-18 19:03:03 | 2024-03-18 19:03:03 |
Judging History
answer
#include <bits/stdc++.h>
#define ff first
#define ss second
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int MAXN = 1e5;
int TC, N, A[MAXN+10];
struct Data
{
int sz;
vector<int> comp;
vector<int> tree;
ll val;
Data()
{
sz=0;
comp.clear();
tree.clear();
val=0;
}
Data(int l, int r)
{
vector<int> V;
for(int i=l; i<=r; i++) V.push_back(A[i]);
sort(V.begin(), V.end());
V.erase(unique(V.begin(), V.end()), V.end());
sz=V.size(); comp=V;
tree=vector<int>(sz+1);
val=0;
for(int i=r; i>=l; i--)
{
val+=query(A[i]-1);
update(A[i], 1);
}
}
int getcomp(int i)
{
int x=lower_bound(comp.begin(), comp.end(), i)-comp.begin();
if(x<comp.size() && comp[x]==i) return x+1;
else return x;
}
void update(int i, int k)
{
i=getcomp(i);
for(; i<=sz; i+=(i&-i)) tree[i]+=k;
}
int query(int i)
{
i=getcomp(i);
int ret=0;
for(; i>0; i-=(i&-i)) ret+=tree[i];
return ret;
}
};
Data B[MAXN+10];
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
scanf("%d", &TC);
while(TC--)
{
scanf("%d", &N);
for(int i=1; i<=N; i++) scanf("%d", &A[i]);
set<int> S;
S.insert(N+1);
S.insert(0);
B[N]=Data(1, N);
ll ans=B[N].val;
multiset<ll> MS;
MS.insert(ans);
MS.insert(0);
for(int i=1; i<=N; i++)
{
printf("%lld ", ans);
ll p;
scanf("%lld", &p);
p^=ans;
auto it=S.lower_bound(p);
int r=*it-1, l=*prev(it)+1;
MS.erase(MS.find(B[r].val));
if(l==r) continue;
if(p<=(l+r)/2)
{
if(l<=p-1)
{
B[p-1]=Data(l, p-1);
B[r].val-=B[p-1].val;
for(int j=l; j<p; j++) B[r].val-=(A[j]>A[p]);
}
for(int j=l; j<=p; j++) B[r].update(A[j], -1);
for(int j=l; j<=p; j++) B[r].val-=B[r].query(A[j]-1);
}
else
{
swap(B[r], B[p-1]);
if(p+1<=r)
{
B[r]=Data(p+1, r);
B[p-1].val-=B[r].val;
for(int j=p+1; j<=r; j++) B[p-1].val-=(A[p]>A[j]);
}
for(int j=p; j<=r; j++) B[p-1].update(A[j], -1);
for(int j=p; j<=r; j++) B[p-1].val-=B[p-1].query(N)-B[p-1].query(A[j]);
}
if(l<=p-1) MS.insert(B[p-1].val);
if(p+1<=r) MS.insert(B[r].val);
S.insert(p);
ans=*prev(MS.end());
}
for(int i=1; i<=N; i++) B[i]=Data();
printf("\n");
}
}
这程序好像有点Bug,我给组数据试试?
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 10288kb
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: 1562ms
memory: 20468kb
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:
ok 11116 lines
Extra Test:
score: 0
Extra Test Passed