Submission #239818

# Submission time Handle Problem Language Result Execution time Memory
239818 2020-06-17T10:45:10 Z mhy908 Pilot (NOI19_pilot) C++14
40 / 100
1000 ms 46968 KB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#define eb emplace_back
using namespace std;
typedef long long LL;
int n, q;
vector<int> vc[1000010];
LL ans[1000010], nans, tmp, sz[1000010];
bool ch[1000010];
int par[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;
}
inline int readChar();
template<class T=int> inline T readInt();
template<class T> inline void writeInt(T x, char end=0);
inline void writeChar(int x);
inline void writeWord(const char *s);
static const int buf_size=4096;
inline int getChar(){
    static char buf[buf_size];
    static int len=0, pos=0;
    if(pos==len)pos=0, len=fread(buf, 1, buf_size, stdin);
    if(pos==len)return -1;
    return buf[pos++];
}
inline int readChar(){
    int c=getChar();
    while(c<=32)c=getChar();
    return c;
}
template <class T>
inline T readInt(){
    int s=1, c=readChar();
    T x=0;
    if(c=='-')s=-1, c=getChar();
    while('0'<= c&&c<='9')x=x*10+c-'0', c=getChar();
    return s==1?x:-x;
}
int main(){
    n=readInt();
    q=readInt();
    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=readInt();
        vc[a].eb(i);
    }
    for(int i=1; i<=1000000; i++){
        for(auto j:vc[i]){
            ch[j]=true;
            if(ch[j+1])mergepar(j, j+1);
            if(ch[j-1])mergepar(j-1, j);
            tmp--;
        }
        ans[i]=nans-tmp;
    }
    for(int i=1; i<=q; i++){
        int a=readInt();
        scanf("%d", &a);
        printf("%lld\n", ans[a]);
    }
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a);
         ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 31 ms 43392 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 35 ms 43392 KB Output is correct
14 Correct 36 ms 43392 KB Output is correct
15 Correct 32 ms 43392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 31 ms 43392 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 35 ms 43392 KB Output is correct
14 Correct 36 ms 43392 KB Output is correct
15 Correct 32 ms 43392 KB Output is correct
16 Correct 31 ms 43392 KB Output is correct
17 Correct 37 ms 43384 KB Output is correct
18 Correct 31 ms 43392 KB Output is correct
19 Correct 38 ms 43392 KB Output is correct
20 Correct 43 ms 43384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 31 ms 43392 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 35 ms 43392 KB Output is correct
14 Correct 36 ms 43392 KB Output is correct
15 Correct 32 ms 43392 KB Output is correct
16 Correct 31 ms 43392 KB Output is correct
17 Correct 37 ms 43384 KB Output is correct
18 Correct 31 ms 43392 KB Output is correct
19 Correct 38 ms 43392 KB Output is correct
20 Correct 43 ms 43384 KB Output is correct
21 Execution timed out 1089 ms 43392 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 51 ms 45432 KB Output is correct
2 Correct 66 ms 46456 KB Output is correct
3 Correct 56 ms 45304 KB Output is correct
4 Correct 70 ms 46116 KB Output is correct
5 Correct 48 ms 45304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 1091 ms 46840 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1096 ms 46968 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 51 ms 45432 KB Output is correct
12 Correct 66 ms 46456 KB Output is correct
13 Correct 56 ms 45304 KB Output is correct
14 Correct 70 ms 46116 KB Output is correct
15 Correct 48 ms 45304 KB Output is correct
16 Correct 64 ms 45304 KB Output is correct
17 Correct 91 ms 46456 KB Output is correct
18 Correct 71 ms 46456 KB Output is correct
19 Correct 48 ms 45440 KB Output is correct
20 Correct 96 ms 46328 KB Output is correct
21 Correct 58 ms 45304 KB Output is correct
22 Correct 68 ms 46200 KB Output is correct
23 Correct 51 ms 45436 KB Output is correct
24 Correct 74 ms 46200 KB Output is correct
25 Correct 49 ms 45432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 31 ms 43392 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 35 ms 43392 KB Output is correct
14 Correct 36 ms 43392 KB Output is correct
15 Correct 32 ms 43392 KB Output is correct
16 Correct 31 ms 43392 KB Output is correct
17 Correct 37 ms 43384 KB Output is correct
18 Correct 31 ms 43392 KB Output is correct
19 Correct 38 ms 43392 KB Output is correct
20 Correct 43 ms 43384 KB Output is correct
21 Execution timed out 1089 ms 43392 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 31 ms 43392 KB Output is correct
2 Correct 32 ms 43384 KB Output is correct
3 Correct 32 ms 43392 KB Output is correct
4 Correct 31 ms 43392 KB Output is correct
5 Correct 31 ms 43392 KB Output is correct
6 Correct 31 ms 43392 KB Output is correct
7 Correct 32 ms 43392 KB Output is correct
8 Correct 30 ms 43392 KB Output is correct
9 Correct 31 ms 43392 KB Output is correct
10 Correct 35 ms 43384 KB Output is correct
11 Correct 31 ms 43392 KB Output is correct
12 Correct 31 ms 43392 KB Output is correct
13 Correct 35 ms 43392 KB Output is correct
14 Correct 36 ms 43392 KB Output is correct
15 Correct 32 ms 43392 KB Output is correct
16 Correct 31 ms 43392 KB Output is correct
17 Correct 37 ms 43384 KB Output is correct
18 Correct 31 ms 43392 KB Output is correct
19 Correct 38 ms 43392 KB Output is correct
20 Correct 43 ms 43384 KB Output is correct
21 Execution timed out 1089 ms 43392 KB Time limit exceeded
22 Halted 0 ms 0 KB -