QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#178647 | #7108. Couleur | PlentyOfPenalty# | AC ✓ | 1237ms | 23460kb | C++17 | 3.0kb | 2023-09-14 10:25:21 | 2023-09-14 10:25:21 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
typedef long long ll;
typedef std::pair<int,int> pii;
const int MAXN = 100011;
struct BIT
{
std::vector<int>t;
#define lowb (i&-i)
int n;
void init(int l)
{
n=l;
t.clear(),t.resize(l+1);
}
void modify(int i,int k)
{
while(i<=n)t[i]+=k,i+=lowb;
}
int Qsum(int i)
{
int res=0;
while(i)res+=t[i],i-=lowb;
return res;
}
}bt[MAXN];
ll val[MAXN];
std::vector<int>seq[MAXN];
std::map<pii,int>S;
std::multiset<ll>ans;
int a[MAXN],cnt;
int place(auto& q,int val)
{
return std::lower_bound(q.begin(),q.end(),val)-q.begin()+1;
}
void brute(int l,int r)
{
//printf("brute[%d,%d]\n",l,r);
if(l>r)return;
int cur=++cnt;
bt[cur].init(r-l+1);
auto &q=seq[cur];
q.resize(r-l+1);
for(int i=l;i<=r;++i)q[i-l]=a[i];
std::sort(q.begin(),q.end());
q.resize(std::unique(q.begin(),q.end())-q.begin());
val[cur]=0;
for(int i=r;i>=l;--i)
{
//printf("i=%d,a[i]=%d\n",i,a[i]);
int x=place(q,a[i]);
//printf("x=%d\n",x);
val[cur]+=bt[cur].Qsum(x-1);
bt[cur].modify(x,1);
}
ans.insert(val[cur]);
S[pii(l,r)]=cur;
//printf("Quit!\n");
}
int main()
{
int task;
scanf("%d",&task);
while(task--)
{
S.clear(),ans.clear();
int n;
scanf("%d",&n);
for(int i=1;i<=n;++i)scanf("%d",&a[i]);
brute(1,n);
for(int w=1;w<=n;++w)
{
ll res=ans.size()?*--ans.end():0;
printf("%lld ",res);
int p;
scanf("%d",&p);
p=p^res;
auto it=--S.lower_bound(pii(p+1,0));
int l=it->first.first,r=it->first.second;
int cur=it->second;
//printf("[%d,%d,%d]\n",l,r,cur);
ans.erase(ans.find(val[cur]));
ll rest=val[cur];
if(p-l<=r-p)
{
for(int i=l;i<=p;++i)
{
int x=place(seq[cur],a[i]);
rest-=bt[cur].Qsum(x-1);
bt[cur].modify(x,-1);
}
S.erase(it);
S[pii(p+1,r)]=cur;
val[cur]=rest;
brute(l,p-1);
}
else
{
for(int i=r;i>=p;--i)
{
int x=place(seq[cur],a[i]);
rest-= i-l+1-bt[cur].Qsum(x);
bt[cur].modify(x,-1);
}
S.erase(it);
S[pii(l,p-1)]=cur;
val[cur]=rest;
brute(p+1,r);
}
ans.insert(val[cur]);
//puts("ok!");
}
puts("");
while(cnt)bt[cnt].init(0),seq[cnt].clear(),--cnt;
}
return 0;
}
这程序好像有点Bug,我给组数据试试?
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 10056kb
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: 1237ms
memory: 23460kb
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