QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#720068#8749. 贸易sdmrlh#WA 100ms343680kbC++14950b2024-11-07 10:30:382024-11-07 10:30:38

Judging History

This is the latest submission verdict.

  • [2024-11-07 10:30:38]
  • Judged
  • Verdict: WA
  • Time: 100ms
  • Memory: 343680kb
  • [2024-11-07 10:30:38]
  • Submitted

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],c[N],a[N],b[N];
stack<int>st[N];
//
//


void solve()
{
	int m,n;
	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<=m;i++)
	{
		if(a[i]==0) st[b[i]].push(i),f[i]=f[i-1];
		else 
		{
			if(!st[b[i]].size()) continue;
			int t = st[b[i]].top();
			c[t+1]++,c[i]--;
			f[i]=f[i-1]+1;
			st[b[i]].pop();
		}
	}
	
	for(int i=1;i<=m;i++) c[i]+=c[i-1];	
	while(n--)
	{
		int l,r;
		cin>>l>>r;
		cout<<f[r]-f[l]-c[l]<<endl;
	}
}
signed main()
{
	IOS;
	int _=1;
	while(_--)
		solve();
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 55ms
memory: 343680kb

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: 100ms
memory: 339556kb

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
-1
0
1
1
3
5
3
0
1
3
2
1
0
0
0
3
5
3
0
3
1
0
1
1
4
1
2
2
1
-1
0
1
3
0
0
3
1
0
1
4
-1
1
0
5
3
1
-1
1
0
0
1
0
5
3
5
5
5
2
3
2
2
2
0
4
1
0
0
6
5
1
2
2
5
4
1
1
1
1
3
1
2
5
1
2
1
-1
0
5
0
1
4
3
5
0
4
2
3
-1
2
3
1
1
1
1
5
0
2
3
0
6
1
1
5
0
0
4
2
0
6
3
0
-1
1
2
0
2
1
0...

result:

wrong answer 20th lines differ - expected: '0', found: '-1'