QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#417841 | #6533. Traveling in Cells | acang | TL | 4626ms | 63884kb | C++14 | 3.5kb | 2024-05-22 23:23:43 | 2024-05-22 23:23:44 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+10;
int C[maxn],V[maxn];
int a[maxn];
#define int long long
#define lc 2*rt
#define rc 2*rt+1
struct node {
int l,r;
int vsum,c;
unordered_map<int,int> mp;
}seg[4*maxn];
void pushup(int rt) {
seg[rt].vsum = seg[lc].vsum + seg[rc].vsum;
}
void build(int rt,int l,int r) {
seg[rt].l = l;
seg[rt].r = r;
seg[rt].mp.clear();
if(l==r) {
seg[rt].vsum = V[l];
seg[rt].mp[C[l]] = 1;
seg[rt].c = C[l];
return;
}
int mid = (l+r)>>1;
build(lc,l,mid);
build(rc,mid+1,r);
pushup(rt);
for(auto pr:seg[lc].mp) {
seg[rt].mp[pr.first] += pr.second;
}
for(auto pr:seg[rc].mp) {
seg[rt].mp[pr.first] += pr.second;
}
}
void vchange(int tar,int rt,int l,int r,int v) {
if(tar == l && l == r) {
seg[rt].vsum = v;
return;
}
int mid = (l+r)>>1;
if(tar<=mid) vchange(tar,lc,l,mid,v);
else vchange(tar,rc,mid+1,r,v);
pushup(rt);
}
void cchange(int tar,int rt,int l,int r,int c,int prec) {
seg[rt].mp[prec]--;
seg[rt].mp[c]++;
if(tar == l && l == r) {
seg[rt].c = c;
C[l] = c;
return;
}
int mid = (l+r)>>1;
if(tar<=mid) cchange(tar,lc,l,mid,c,prec);
else cchange(tar,rc,mid+1,r,c,prec);
}
bool getcsum(int rt,int tarl,int tarr,int l,int r,int k) {
if(tarl<=l&&r<=tarr) {
int sum=0;
for(int i=1;i<=k;i++) {
sum += seg[rt].mp[a[i]];
}
return sum==(seg[rt].r-seg[rt].l+1);
}
int mid = (l+r)>>1;
bool sum = true;
if(tarl<=mid) sum &= getcsum(lc,tarl,tarr,l,mid,k);
if(tarr>mid) sum &= getcsum(rc,tarl,tarr,mid+1,r,k);
pushup(rt);
return sum;
}
int getvsum(int rt,int tarl,int tarr,int l,int r,int k) {
if(tarl<=l&&r<=tarr) {
return seg[rt].vsum;
}
int mid = (l+r)>>1;
int sum = 0;
if(tarl<=mid) sum += getvsum(lc,tarl,tarr,l,mid,k);
if(tarr>mid) sum += getvsum(rc,tarl,tarr,mid+1,r,k);
pushup(rt);
return sum;
}
void solve() {
int n,q;
cin>>n>>q;
for(int i=1;i<=n;i++) {
cin>>C[i];
}
for(int i=1;i<=n;i++) {
cin>>V[i];
}
build(1,1,n);
while(q--) {
int op;
cin>>op;
if(op == 1) {
int pos,x;
cin>>pos>>x;
int prec = C[pos];
cchange(pos,1,1,n,x,prec);
}
if(op == 2) {
int pos,x;
cin>>pos>>x;
vchange(pos,1,1,n,x);
}
if(op == 3) {
int x,k;
cin>>x>>k;
for(int i=1;i<=k;i++) {
cin>>a[i];
}
int l=1,r=x;
while (l<r) {
int mid = (l+r)>>1;
bool ans = getcsum(1,mid,x,1,n,k);
if(ans) r = mid;
else l= mid + 1;
}
int L = l;
l=x,r=n;
while (l<r) {
int mid = (l+r+1)>>1;
bool ans = getcsum(1,x,mid,1,n,k);
if(ans) l = mid;
else r = mid - 1;
}
int R = l;
cout<<getvsum(1,L,R,1,n,k)<<'\n';
}
}
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int __t=1;
cin>>__t;
while(__t--) {
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 5ms
memory: 38304kb
input:
2 5 10 1 2 3 1 2 1 10 100 1000 10000 3 3 1 3 3 3 2 2 3 2 5 20000 2 3 200 3 3 2 1 3 3 3 3 1 2 3 1 3 4 2 1 100000 1 2 2 3 1 2 1 2 4 1 1 2 3 4 1000000 1000000 1000000 1000000 3 4 4 1 2 3 4
output:
100 110 1200 21211 100010 4000000
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 336ms
memory: 38420kb
input:
20000 15 15 1 1 3 3 2 3 3 3 3 3 2 3 2 3 3 634593973 158136379 707704004 998369647 831633445 263092797 937841412 451774682 552617416 483763379 50360475 794662797 74247465 537217773 901809831 3 6 4 1 3 5 10 3 5 7 1 2 3 4 5 9 10 3 4 3 3 8 9 2 13 608033129 3 15 2 3 5 1 9 3 3 8 4 1 3 7 10 2 6 727472865 3...
output:
2689089686 8377825475 1706073651 1439027604 2689089686 792730352 8904867081 8904867081 8270273108 831633445 692051585 2782432626 697783016 883944422 184057757 287523250 184057757 696388752 184057757 1675459344 2667693025 2614711258 4006992373 1767091974 5348541057 5348541057 390631780 2290216252 942...
result:
ok 200062 numbers
Test #3:
score: 0
Accepted
time: 659ms
memory: 38004kb
input:
2000 150 150 8 3 8 8 8 6 8 4 2 7 6 8 8 5 8 7 7 8 5 6 8 8 6 8 8 8 8 7 8 6 6 8 8 8 6 2 3 4 8 8 7 8 5 8 2 6 8 7 8 8 6 8 6 8 3 8 8 8 8 4 7 8 7 3 7 6 7 5 5 8 6 8 8 6 3 8 6 7 6 8 8 7 4 8 6 7 8 7 7 7 7 8 8 8 8 2 5 2 8 8 6 7 6 3 8 8 7 8 8 8 6 6 8 6 6 7 5 8 8 8 7 8 7 7 6 8 8 8 8 8 8 6 5 7 5 5 8 7 8 7 7 7 6 5...
output:
4449391171 3290849667 852793841 5178673994 995994209 11431868919 4327723427 5071541023 3032743466 962345334 2997656427 4534278452 3851900075 3611231417 5071541023 1477584218 1299005818 1299005818 2145605244 854143763 886347565 2081234124 2333808475 2455955801 4179722063 2328504333 1473735464 4107685...
result:
ok 199987 numbers
Test #4:
score: 0
Accepted
time: 4626ms
memory: 63884kb
input:
10 30000 30000 3 4 2 4 4 4 4 3 4 3 4 3 4 3 4 4 2 4 4 4 4 4 3 3 3 4 3 4 3 4 3 3 4 2 4 3 3 3 3 4 3 4 4 4 4 2 3 3 4 2 3 4 4 4 4 1 4 4 4 4 4 4 4 4 3 3 3 4 4 4 4 4 2 3 4 4 4 4 3 4 4 3 3 3 4 4 3 4 4 2 3 4 4 4 4 3 2 4 3 4 3 2 4 4 3 4 2 2 4 4 4 4 2 4 3 2 4 4 3 4 4 4 2 4 4 3 2 3 2 3 3 3 4 2 4 3 4 1 4 3 4 4 4...
output:
6959437173 934970676 72461245502 8365928740 8384151048 984567228 12482909122 1904927816 15134139942 3759040688 92670874909 332468911 5936663371 3562978848 1300592004 10314009201 5581540905 131246926443 15087184135864 4077066271 1124704817 1520626740 4388174158 744377942 2770411457 6231852240 1508724...
result:
ok 200135 numbers
Test #5:
score: -100
Time Limit Exceeded
input:
3 100000 100000 6 6 2 6 5 3 6 5 4 6 4 6 6 6 6 5 2 5 2 6 6 6 1 6 5 6 4 5 6 6 5 4 5 4 3 4 5 5 6 6 5 6 6 5 2 5 6 5 4 2 5 6 6 6 5 2 5 6 6 4 5 6 3 3 6 5 6 5 5 5 5 4 4 4 4 3 6 5 4 5 6 5 6 6 6 6 3 6 5 6 5 4 3 5 6 4 5 3 6 5 3 5 6 4 6 5 4 5 5 5 2 5 4 6 6 3 5 5 5 5 5 4 5 5 6 5 5 6 6 6 5 5 4 6 5 4 4 2 6 6 6 5 ...
output:
753014823 938372065 5655899645 168297301 14372254310 1066586326 3520855082 2591792266 2321844837 64378192092 250581310 1845085639 1402247975 198007248 2157074263 2743531397 3433471688 10332600792 1085086491 4845484125 50019185900042 4036199358 154762798 50019185900042 1221387905 11240790307 10537215...