Submission #402044

# Submission time Handle Problem Language Result Execution time Memory
402044 2021-05-11T08:41:30 Z keta_tsimakuridze Poklon (COCI17_poklon) C++14
0 / 140
1569 ms 45620 KB
#include<bits/stdc++.h>
#define f first
#define int long long
#define s second
using namespace std;
const int N=5e5+5,mod=1e9+7;
int t,n,q,a[N],tree[N],bef[N],ans[N];
map<int,int>pos;
string s;
vector<pair<int,int> >V[N];
void update(int ind,int val){
	for(ind;ind<=n;ind+=ind&(-ind)) tree[ind]+=val;
}
int getans(int ind){
	int pas=0;
	for(ind;ind>=1;ind-=ind&(-ind)) pas+=tree[ind];
	return pas;
}
 main(){
	// t=1;
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=q;i++){
		int l,r;
		cin>>l>>r;
		V[l].push_back({r,i});
	}
	for(int i=n;i>=1;i--){
		
		bef[i]=pos[a[i]];
		if(bef[bef[i]] ) update(bef[bef[i]],-2);
		if(bef[i])update(bef[i],1);
		for(int j=0;j<V[i].size();j++){
			ans[V[i][j].s] = getans(V[i][j].f);
		}
		pos[a[i]] = i;
	}
	for(int i=1;i<=q;i++) cout<<ans[i]<<endl;
}

Compilation message

poklon.cpp: In function 'void update(long long int, long long int)':
poklon.cpp:12:6: warning: statement has no effect [-Wunused-value]
   12 |  for(ind;ind<=n;ind+=ind&(-ind)) tree[ind]+=val;
      |      ^~~
poklon.cpp: In function 'long long int getans(long long int)':
poklon.cpp:16:6: warning: statement has no effect [-Wunused-value]
   16 |  for(ind;ind>=1;ind-=ind&(-ind)) pas+=tree[ind];
      |      ^~~
poklon.cpp: At global scope:
poklon.cpp:19:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   19 |  main(){
      |  ^~~~
poklon.cpp: In function 'int main()':
poklon.cpp:35:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |   for(int j=0;j<V[i].size();j++){
      |               ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12044 KB Output isn't correct
2 Incorrect 9 ms 11980 KB Output isn't correct
3 Incorrect 11 ms 12108 KB Output isn't correct
4 Incorrect 21 ms 12432 KB Output isn't correct
5 Incorrect 293 ms 19404 KB Output isn't correct
6 Incorrect 312 ms 19496 KB Output isn't correct
7 Incorrect 601 ms 25940 KB Output isn't correct
8 Incorrect 908 ms 32552 KB Output isn't correct
9 Incorrect 1218 ms 38996 KB Output isn't correct
10 Incorrect 1569 ms 45620 KB Output isn't correct