Submission #201493

# Submission time Handle Problem Language Result Execution time Memory
201493 2020-02-10T18:35:01 Z awlintqaa Poklon (COCI17_poklon) C++14
Compilation error
0 ms 0 KB
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 340
#define mid (l+r)/2
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
typedef long long ll;
typedef short int si;
typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const ll mod=1e9+7;
const ll inf=1e18;
const ld pai=acos(-1);
int n,q;
int a[500009];
//seg tree
int tree[2000009][2];
void upd(int node,int l,int r,int id,int x,int t){
        if(l==r){
                tree[node][t]+=x;
                return ;
        }
        if(s>r || e<l)return 0;
        if(s<=l && e>=r)return tree[node][t];
        return query(node*2,l,mid,s,e,t)+query(node*2+1,mid+1,r,s,e,t);
}
//filling last1 & last2
map<int,int>mp;
int last[500009][2];
void fill(){
        for(int i=1;i<=n;i++){
                last[i][0]=mp[a[i]];
                last[i][1]=last[last[i][0]][0];
                mp[a[i]]=i;
        }
}

//calc ans
vpi v[500009];
map<int,int>bef;
int ans[500009];
void solve(){
        for(int i=1;i<=n;i++){
                upd(1,0,n,last[i][0],1,0);
                upd(1,0,n,last[i][1],1,1);
                if(bef[a[i]]){
                        int id=bef[a[i]];
                        upd(1,0,n,last[id][0],-1,0);
                        upd(1,0,n,last[id][1],-1,1);
                }
                bef[a[i]]=i;
                for(auto u:v[i]){
                        int l=u.fi;
                        int id=u.se;
                        ans[id]=query(1,0,n,0,l-1,1)-query(1,0,n,0,l-1,0);
                }
        }
}
int main(){
        cin>>n>>q;
        for(int i=1;i<=n;i++)cin>>a[i];
        fill();
        for(int i=0;i<q;i++){
                int l,r;
                cin>>l>>r;
                v[r].pb({l,i});
        }
        solve();
        for(int i=0;i<q;i++)cout<<ans[i]<<endl;
}

Compilation message

poklon.cpp: In function 'void upd(int, int, int, int, int, int)':
poklon.cpp:38:12: error: 's' was not declared in this scope
         if(s>r || e<l)return 0;
            ^
poklon.cpp:38:19: error: 'e' was not declared in this scope
         if(s>r || e<l)return 0;
                   ^
poklon.cpp:38:30: error: return-statement with a value, in function returning 'void' [-fpermissive]
         if(s>r || e<l)return 0;
                              ^
poklon.cpp:39:12: error: 's' was not declared in this scope
         if(s<=l && e>=r)return tree[node][t];
            ^
poklon.cpp:39:20: error: 'e' was not declared in this scope
         if(s<=l && e>=r)return tree[node][t];
                    ^
poklon.cpp:39:44: error: return-statement with a value, in function returning 'void' [-fpermissive]
         if(s<=l && e>=r)return tree[node][t];
                                            ^
poklon.cpp:40:35: error: 's' was not declared in this scope
         return query(node*2,l,mid,s,e,t)+query(node*2+1,mid+1,r,s,e,t);
                                   ^
poklon.cpp:40:37: error: 'e' was not declared in this scope
         return query(node*2,l,mid,s,e,t)+query(node*2+1,mid+1,r,s,e,t);
                                     ^
poklon.cpp:40:16: error: 'query' was not declared in this scope
         return query(node*2,l,mid,s,e,t)+query(node*2+1,mid+1,r,s,e,t);
                ^~~~~
poklon.cpp:40:70: error: return-statement with a value, in function returning 'void' [-fpermissive]
         return query(node*2,l,mid,s,e,t)+query(node*2+1,mid+1,r,s,e,t);
                                                                      ^
poklon.cpp: In function 'void solve()':
poklon.cpp:70:33: error: 'query' was not declared in this scope
                         ans[id]=query(1,0,n,0,l-1,1)-query(1,0,n,0,l-1,0);
                                 ^~~~~