제출 #401516

#제출 시각아이디문제언어결과실행 시간메모리
401516NintsiChkhaidzePoklon (COCI17_poklon)C++14
28 / 140
167 ms40588 KiB
#include <bits/stdc++.h>
#define pb push_back
#define s second
#define f first
#define ll long long
#define int long long
#define left (node<<1),l,((l+r)>>1)
#define right ((node<<1)|1),((l+r)>>1) + 1,r
using namespace std;
const int Bl = 707,N = 500005;
pair<pair<int,int>,int> d[N];
int ans[N],res,a[N];
map <int,int> cnt;
bool cmp(pair<pair<int,int>,int> a,pair<pair<int,int>,int> b){
    if (a.f.f/Bl == b.f.f/Bl) 
        return a.f.s < b.f.s;
    return a.f.f/Bl < b.f.f<Bl;
}
void add(int ind){
    if (cnt[a[ind]] == 2) res--;
    cnt[a[ind]]++;
    if(cnt[a[ind]] == 2) res++;
}
void remove(int ind){
    if (cnt[a[ind]] == 2) res--;
    cnt[a[ind]]--;
    if(cnt[a[ind]] == 2) res++;
}
main (){
    ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    
    for (int i=1;i<=n;i++)
        cin>>a[i];
    
    for (int i=1;i<=m;i++){
        int l,r;
        cin>>l>>r;
        d[i] = {{l,r},i};
    }
    
    sort(d+1,d+m+1,cmp);
    
    int L = 0,R = -1;
    for (int i=1;i<=m;i++){
        int l = d[i].f.f,r = d[i].f.s,idx = d[i].s;
        while (L > l) add(--L);
        while (R < r) add(++R);
        while (L < l) remove(L++);
        while (R > r) remove(R--);
        ans[idx] = res;
    }
    
    for (int i=1;i<=m;i++)
        cout<<ans[i]<<"\n";
}

컴파일 시 표준 에러 (stderr) 메시지

poklon.cpp: In function 'bool cmp(std::pair<std::pair<long long int, long long int>, long long int>, std::pair<std::pair<long long int, long long int>, long long int>)':
poklon.cpp:17:28: warning: comparison of constant '707' with boolean expression is always true [-Wbool-compare]
   17 |     return a.f.f/Bl < b.f.f<Bl;
      |            ~~~~~~~~~~~~~~~~^~~
poklon.cpp:17:21: warning: comparisons like 'X<=Y<=Z' do not have their mathematical meaning [-Wparentheses]
   17 |     return a.f.f/Bl < b.f.f<Bl;
      |                     ^
poklon.cpp: At global scope:
poklon.cpp:29:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   29 | main (){
      |       ^
#Verdict Execution timeMemoryGrader output
Fetching results...