QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#432875 | #8749. 贸易 | LiWenX# | WA | 54ms | 11860kb | C++20 | 931b | 2024-06-07 19:29:41 | 2024-06-07 19:29:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,q;
vector<int> vec[500005];
struct BIT{
int c[500005];
#define lb(x) (x&-x)
void add(int x){
while(x){
c[x]++;
x-=lb(x);
}
}
int ask(int x){
int ret=0;
while(x<=n){
ret+=c[x];
x+=lb(x);
}return ret;
}
}T;
int a[500005],c[500005];
vector<pair<int,int> > V[500005];
int ans[500005];
int main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>c[i];
}
for(int i=1;i<=q;i++){
int l,r;cin>>l>>r;
V[r].push_back(make_pair(l,i));
}
for(int i=1;i<=n;i++){
if(a[i]==0){
vec[c[i]].push_back(i);
}
else{
if(!vec[c[i]].size()) continue;
T.add(vec[c[i]].back());
vec[c[i]].pop_back();
}
for(auto u:V[i]){
ans[u.second]=T.ask(u.first);
}
}
for(int i=1;i<=q;i++){
cout<<ans[i]<<'\n';
}
}
详细
Test #1:
score: 100
Accepted
time: 2ms
memory: 5672kb
input:
10 5 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 4 6 2 4 2 6 7 10 4 7
output:
0 0 0 1 0
result:
ok 5 lines
Test #2:
score: 0
Accepted
time: 45ms
memory: 9836kb
input:
20 500000 1 0 0 1 0 0 0 0 1 0 1 0 1 0 1 0 1 0 0 0 1 2 1 2 2 1 1 2 1 1 1 2 2 1 2 2 2 1 1 2 13 20 8 9 1 7 5 13 3 10 3 19 14 15 1 5 9 17 7 10 6 6 8 20 1 17 13 20 4 6 16 20 7 14 2 16 3 17 11 12 1 1 15 20 11 15 2 12 2 15 8 16 9 12 9 13 10 19 12 19 9 13 4 8 2 2 19 19 9 17 4 20 4 14 4 8 6 13 13 17 15 16 13...
output:
1 0 1 3 1 5 0 1 3 1 0 4 6 1 0 1 3 5 5 0 0 1 1 3 5 3 1 2 3 2 2 0 0 0 3 5 3 0 3 1 0 1 1 4 2 2 2 1 0 0 2 3 1 0 3 1 0 1 4 0 1 0 5 3 1 0 1 1 1 1 0 5 3 5 5 5 2 3 2 2 2 0 4 2 0 1 6 5 1 2 2 5 4 1 1 1 1 3 1 2 5 1 2 1 0 0 5 0 1 4 3 5 0 4 2 3 0 2 3 1 1 1 1 5 0 2 3 0 6 1 1 5 0 1 4 2 0 6 3 1 0 1 2 0 2 1 0 0 0 0 ...
result:
ok 500000 lines
Test #3:
score: -100
Wrong Answer
time: 54ms
memory: 11860kb
input:
30 500000 1 0 1 1 0 1 1 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 1 1 0 0 0 1 0 1 2 3 2 1 2 1 3 2 1 3 1 2 3 1 2 1 3 2 3 2 1 2 1 2 1 1 1 2 3 2 5 19 3 25 8 23 17 19 15 26 3 27 1 10 25 30 16 22 11 21 17 29 21 30 11 26 3 27 21 22 17 23 1 14 5 21 24 27 8 20 15 29 13 25 11 19 5 15 7 18 24 28 7 26 3 24 14 26 4 5 11 19...
output:
3 6 5 0 3 6 0 0 1 2 3 1 5 6 0 2 2 3 0 3 4 5 2 1 3 0 6 6 4 0 2 5 8 7 1 3 0 5 2 2 2 0 2 3 0 2 3 4 0 0 3 6 2 0 6 3 3 3 5 6 0 2 4 3 3 0 0 1 2 0 0 3 3 4 1 6 2 2 0 3 0 4 1 3 0 2 2 6 2 0 1 6 4 4 2 0 0 0 1 6 6 0 1 0 0 0 0 1 3 6 2 0 4 3 0 5 8 7 1 1 6 0 6 3 3 0 4 3 1 0 8 4 5 3 3 0 0 0 2 3 6 5 3 5 0 0 2 7 4 2 ...
result:
wrong answer 7th lines differ - expected: '1', found: '0'