Submission #402041

# Submission time Handle Problem Language Result Execution time Memory
402041 2021-05-11T08:39:17 Z keta_tsimakuridze Poklon (COCI17_poklon) C++14
0 / 140
799 ms 53060 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]<<" ";
}

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 9 ms 11980 KB Output isn't correct
2 Incorrect 9 ms 12108 KB Output isn't correct
3 Incorrect 9 ms 12108 KB Output isn't correct
4 Incorrect 13 ms 12364 KB Output isn't correct
5 Incorrect 128 ms 19916 KB Output isn't correct
6 Incorrect 143 ms 19880 KB Output isn't correct
7 Incorrect 344 ms 28152 KB Output isn't correct
8 Incorrect 471 ms 36548 KB Output isn't correct
9 Incorrect 631 ms 44752 KB Output isn't correct
10 Incorrect 799 ms 53060 KB Output isn't correct