QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#424409 | #8749. 贸易 | zjy0001 | WA | 55ms | 20904kb | C++17 | 1.1kb | 2024-05-29 09:35:08 | 2024-05-29 09:35:08 |
Judging History
answer
#include<bits/stdc++.h>
#define LL long long
#define LLL __int128
#define uint unsigned
#define ldb long double
#define uLL unsigned long
using namespace std;
const int N=2e5+5,BL=450;
const LL INF=1e18+7;
int n,q;
vector<int>vec[N];
vector<pair<int,int>>Q[N];
int a[N],b[N],c[N],pre[N],ans[N];
inline void add(int x,int y){
for(;x;x-=x&-x)c[x]+=y;
}
inline int sum(int x){
int z=0;for(;x<=n;x+=x&-x)z+=c[x];return z;
}
signed main(){
cin.tie(0)->sync_with_stdio(0);
cin>>n>>q;
for(int i=1;i<=n;++i)cin>>a[i];
for(int i=1;i<=n;++i){
cin>>b[i];
if(a[i]){
if(!vec[b[i]].empty())pre[i]=vec[b[i]].back(),vec[b[i]].pop_back();
else pre[i]=0;
}
else{
pre[i]=0;
vec[b[i]].emplace_back(i);
}
}
for(int i=1;i<=q;++i){
int l,r;cin>>l>>r;
Q[r].emplace_back(l,i);
}
for(int i=1;i<=n;++i){
add(pre[i],1);
for(const auto&[l,id]:Q[i])ans[id]=sum(l);
}
for(int i=1;i<=q;++i)cout<<ans[i]<<'\n';
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 16212kb
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: -100
Wrong Answer
time: 55ms
memory: 20904kb
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:
8 0 1 4 1 23 1 1 6 1 0 10 7 8 0 7 3 6 4 0 0 8 4 3 5 3 1 2 15 8 2 0 0 26 6 25 3 0 4 1 1 8 0 4 2 2 2 1 1 1 2 4 4 0 3 1 26 1 5 1 7 0 4 3 1 1 1 4 4 1 0 12 6 6 11 11 11 3 6 8 2 33 4 2 0 1 29 12 1 2 2 11 5 1 8 1 1 4 7 2 5 1 2 1 0 1 11 0 1 4 6 12 0 4 1 4 0 8 3 8 1 1 7 5 0 2 3 0 15 1 1 23 0 1 4 2 26 25 3 1 ...
result:
wrong answer 1st lines differ - expected: '1', found: '8'