Submission #239816

# Submission time Handle Problem Language Result Execution time Memory
239816 2020-06-17T10:42:51 Z mhy908 Pilot (NOI19_pilot) C++14
Compilation error
0 ms 0 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define svec(x) sort(x.begin(), x.end())
#define press(x) x.erase(unique(x.begin(), x.end()), x.end())
#define lb(x, v) lower_bound(x.begin(), x.end(), v)
#define ub(x, v) upper_bound(x.begin(), x.end(), v)
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=2000000000000000000;
const LL mod1=1000000007;
const LL mod2=998244353;
const int inf=2000000000;
int n, q;
vector<int> vc[1000010];
LL ans[1000010], nans, tmp;
bool ch[1000010];
int par[1000010];
LL sz[1000010];
int findpar(int num){return num==par[num]?num:par[num]=findpar(par[num]);}
void mergepar(int a, int b){
    a=findpar(a);
    b=findpar(b);
    if(a==b)return;
    nans-=sz[a]*(sz[a]+1)/2;
    nans-=sz[b]*(sz[b]+1)/2;
    sz[a]+=sz[b];
    par[b]=a;
    nans+=sz[a]*(sz[a]+1)/2;
}
int main(){
    scanf("%d %d", &n, &q);
    for(int i=1; i<=1000000; i++)par[i]=i, sz[i]=1;
    nans=(LL)n;
    tmp=(LL)n;
    for(int i=1; i<=n; i++){
        int a;
        scanf("%d", &a);
        vc[a].eb(i);
    }
    for(int i=1; i<=1000000; i++){
        for(auto j:vc[i]){
            ch[j]=true;
            if(ch[j+1])uf.mergepar(j, j+1);
            if(ch[j-1])uf.mergepar(j-1, j);
            tmp--;
        }
        ans[i]=nans-tmp;
    }
    for(int i=1; i<=q; i++){
        int a;
        scanf("%d", &a);
        printf("%lld\n", ans[a]);
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:54:24: error: 'uf' was not declared in this scope
             if(ch[j+1])uf.mergepar(j, j+1);
                        ^~
pilot.cpp:54:24: note: suggested alternative: 'ub'
             if(ch[j+1])uf.mergepar(j, j+1);
                        ^~
                        ub
pilot.cpp:55:24: error: 'uf' was not declared in this scope
             if(ch[j-1])uf.mergepar(j-1, j);
                        ^~
pilot.cpp:55:24: note: suggested alternative: 'ub'
             if(ch[j-1])uf.mergepar(j-1, j);
                        ^~
                        ub
pilot.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
pilot.cpp:48:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
pilot.cpp:62:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~