Submission #861039

# Submission time Handle Problem Language Result Execution time Memory
861039 2023-10-15T07:41:23 Z Dzadzo Poklon (COCI17_poklon) C++17
0 / 140
589 ms 57440 KB
#include <bits/stdc++.h>
#define ll long long
#define int ll
#define pb push_back
#define S second
#define F first
#define pii pair<int,int>
#define vi vector <int>
#define vvi vector <vi>
#define vvvi vector <vvi>
#define vp vector <pii>
#define vvp vector <vp>
#define vb vector <bool>
#define vvb vector <vb>;
#define INF LLONG_MAX
#define MOD 1000000009
#define MAXN 500000
#pragma GCC optimize("O3,unroll-loops")
using namespace std;
int t[4*MAXN+1];
void up(int v,int tl,int tr,int pos,int val){
	if (tl==tr)t[v]=val;else{
		int tm=(tl+tr)/2;
		if (pos<=tm)up(v*2,tl,tm,pos,val);else up(v*2+1,tm+1,tr,pos,val);
		t[v]=t[v*2]+t[v*2+1];
	}
}
int query(int v,int tl,int tr,int l,int r){
	if (l>r)return 0;
	if (tl==l && tr==r)return t[v];
	int tm=(tl+tr)/2;
	return query(v*2,tl,tm,l,min(r,tm))+query(v*2+1,tm+1,tr,max(l,tm+1),r);
}
int32_t main() {
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
	int n,q;
	cin>>n>>q;
	int a[n+1];
	for (int i=1;i<=n;i++)cin>>a[i];
	vvp Q(n+1);
	int cnt=0;
	int ans[q+1];
	for (int i=1;i<=q;i++){
		int l,r;
		cin>>l>>r;
		Q[r].pb({l,i});
	}
	map <int,int> f;
	int prev[n+1];
	for (int i=1;i<=n;i++){
		prev[i]=f[a[i]];
	//	cout<<prev[i]<<" ";
		f[a[i]]=i;
	}
	
	for (int i=1;i<=n;i++){
		if (prev[i]){
			up(1,1,n,prev[i],1);
			if (prev[prev[i]]){
				up(1,1,n,prev[prev[i]],-1);
			}
		}
		for (auto &[x,id]:Q[i]){
			ans[id]=query(1,1,n,x,i);
		}
	}
	for (int i=1;i<=q;i++)cout<<ans[i]<<"\n";

}

Compilation message

poklon.cpp: In function 'int32_t main()':
poklon.cpp:41:6: warning: unused variable 'cnt' [-Wunused-variable]
   41 |  int cnt=0;
      |      ^~~
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Incorrect 1 ms 440 KB Output isn't correct
3 Incorrect 1 ms 348 KB Output isn't correct
4 Incorrect 4 ms 988 KB Output isn't correct
5 Incorrect 77 ms 11860 KB Output isn't correct
6 Incorrect 88 ms 11844 KB Output isn't correct
7 Incorrect 199 ms 23948 KB Output isn't correct
8 Incorrect 328 ms 37672 KB Output isn't correct
9 Incorrect 414 ms 47512 KB Output isn't correct
10 Incorrect 589 ms 57440 KB Output isn't correct