QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#720206 | #8749. 贸易 | sdmrlh# | WA | 129ms | 361964kb | C++14 | 1.3kb | 2024-11-07 11:12:44 | 2024-11-07 11:12:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define sf(x) scanf("%lld",&x)
#define sff(x,y) scanf("%lld%lld",&x,&y)
#define endl '\n'
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pf(x) printf("%lld",x)
#define pii pair<int,int>
//#define f first
#define s second
#define int long long
//
const int N = 5e5+10;
int f[N],tr[N],a[N],b[N];
int m,n;
stack<int>st[N];
//
int lowbit(int x)
{
return x & -x;
}
void add(int x, int k)
{
for (int i = x; i <= m; i += lowbit(i))tr[i] += k;
}
int ask(int x)
{
int res = 0;
for (int i = x; i; i -= lowbit(i))res += tr[i];
return res;
}
pii q[N];
vector<int> ve[N];
map<pii,int> mp;
int res[N];
//
void solve()
{
cin>>m>>n;
for(int i=1;i<=m;i++) cin>>a[i];
for(int i=1;i<=m;i++) cin>>b[i];
for(int i=1;i<=n;i++)
{
int l,r;
cin>>l>>r;
ve[r].push_back(l);
mp[{l,r}]=i;
}
for(int i=1;i<=m;i++)
{
if(a[i]==0) st[b[i]].push(i),f[i]=f[i-1];
else
{
if(st[b[i]].size()) {
int t = st[b[i]].top();
add(t+1,1);
add(i,-1);
f[i]=f[i-1]+1;
st[b[i]].pop();
}
else f[i]=f[i-1];
}
for(auto j:ve[i])
res[mp[{j,i}]]=f[i]-f[j]-ask(j);
}
for(int i=1;i<=n;i++) cout<<res[i]<<endl;
}
signed main()
{
IOS;
int _=1;
while(_--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 39ms
memory: 353228kb
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: 129ms
memory: 361964kb
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:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 1st lines differ - expected: '1', found: '0'