Submission #894903

# Submission time Handle Problem Language Result Execution time Memory
894903 2023-12-29T07:39:14 Z adkjt Pilot (NOI19_pilot) C++14
89 / 100
1000 ms 92824 KB
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define ll long long
vector<int> g[1111111];
set<pair<int,int>> s;
int a[1111111];
long long ans[1111111],ind[1111111];
int main()
{
    int n,q,hmx=0;
    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++)
        ind[i]=ind[i-1]+i;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        hmx=max(hmx,a[i]);
        g[a[i]].push_back(i);
    }
    //s.insert({0,0});
    for(int i=1;i<=hmx;i++)
    {
        ans[i]=ans[i-1];
        //printf("Y");
        for(auto x:g[i])
        {
            //printf("OO");
              if(s.empty()){
                ans[i]+=1,s.insert({x,x});
                continue;
            }
            int cnt=1,rch=0,lch=0;
            auto it=s.lower_bound({x,x});
            if(it==s.end()) rch=1;
            auto itr=it;
            if(it!=s.begin())  itr--;



            pair<int,int> left=*itr,right=*it;
            /*for(auto p=s.begin();p!=s.end();p++)
                printf("%d,%d ",(*p).f,(*p).s);*/
            //printf("\n%d %d %d %d %d\n%d %d\n",x,left.f,left.s,right.f,right.s,lch,rch);

            if(!rch&&!lch&&left.s==x-1&&right.f==x+1)
            {
                  ans[i]-=ind[left.s-left.f+1];
                  ans[i]-=ind[right.s-right.f+1];
                  ans[i]+=ind[right.s-left.f+1];
                  s.erase(it);
                  if(itr!=it)
                  s.erase(itr);
                  s.insert({left.f,right.s});
            }
            else if(!rch&&right.f==x+1)
            {
                ans[i]-=ind[right.s-right.f+1];
                ans[i]+=ind[right.s-x+1];
                s.erase(it);
                s.insert({x,right.s});
            }
            else if(!lch&&left.s==x-1)
            {
                ans[i]-=ind[left.s-left.f+1];
                ans[i]+=ind[x-left.f+1];
                s.erase(itr);
                s.insert({left.f,x});
            }
            else
            ans[i]+=1,s.insert({x,x});

            //printf("LL");
        }
    }
    for(int i=1;i<=q;i++)
    {
        int qu;
        scanf("%lld",&qu);
        if(qu>hmx) qu=hmx;
        printf("%lld\n",ans[qu]);
    }
   /* for(int i=1;i<=hmx;i++)
        printf("%lld ",ind[i]);*/
    return 0;
}

Compilation message

pilot.cpp: In function 'int main()':
pilot.cpp:34:17: warning: unused variable 'cnt' [-Wunused-variable]
   34 |             int cnt=1,rch=0,lch=0;
      |                 ^~~
pilot.cpp:80:19: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
   80 |         scanf("%lld",&qu);
      |                ~~~^  ~~~
      |                   |  |
      |                   |  int*
      |                   long long int*
      |                %d
pilot.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     scanf("%d %d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~~
pilot.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
pilot.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |         scanf("%lld",&qu);
      |         ~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 7 ms 29532 KB Output is correct
12 Correct 10 ms 37536 KB Output is correct
13 Correct 11 ms 29528 KB Output is correct
14 Correct 10 ms 37468 KB Output is correct
15 Correct 7 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 7 ms 29532 KB Output is correct
12 Correct 10 ms 37536 KB Output is correct
13 Correct 11 ms 29528 KB Output is correct
14 Correct 10 ms 37468 KB Output is correct
15 Correct 7 ms 29532 KB Output is correct
16 Correct 7 ms 29644 KB Output is correct
17 Correct 12 ms 37496 KB Output is correct
18 Correct 7 ms 29628 KB Output is correct
19 Correct 11 ms 37468 KB Output is correct
20 Correct 6 ms 29532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 7 ms 29532 KB Output is correct
12 Correct 10 ms 37536 KB Output is correct
13 Correct 11 ms 29528 KB Output is correct
14 Correct 10 ms 37468 KB Output is correct
15 Correct 7 ms 29532 KB Output is correct
16 Correct 7 ms 29644 KB Output is correct
17 Correct 12 ms 37496 KB Output is correct
18 Correct 7 ms 29628 KB Output is correct
19 Correct 11 ms 37468 KB Output is correct
20 Correct 6 ms 29532 KB Output is correct
21 Correct 7 ms 29636 KB Output is correct
22 Correct 16 ms 37464 KB Output is correct
23 Correct 7 ms 29532 KB Output is correct
24 Correct 12 ms 37468 KB Output is correct
25 Correct 7 ms 29648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 35988 KB Output is correct
2 Correct 86 ms 44252 KB Output is correct
3 Correct 60 ms 36048 KB Output is correct
4 Correct 72 ms 44120 KB Output is correct
5 Correct 53 ms 36032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 37196 KB Output is correct
2 Correct 42 ms 37092 KB Output is correct
3 Correct 41 ms 37132 KB Output is correct
4 Correct 43 ms 37216 KB Output is correct
5 Correct 40 ms 36944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 44356 KB Output is correct
2 Correct 73 ms 44132 KB Output is correct
3 Correct 61 ms 44112 KB Output is correct
4 Correct 52 ms 44624 KB Output is correct
5 Correct 70 ms 44628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 67 ms 35988 KB Output is correct
12 Correct 86 ms 44252 KB Output is correct
13 Correct 60 ms 36048 KB Output is correct
14 Correct 72 ms 44120 KB Output is correct
15 Correct 53 ms 36032 KB Output is correct
16 Correct 52 ms 35836 KB Output is correct
17 Correct 85 ms 44372 KB Output is correct
18 Correct 75 ms 44368 KB Output is correct
19 Correct 54 ms 35924 KB Output is correct
20 Correct 83 ms 44372 KB Output is correct
21 Correct 61 ms 35780 KB Output is correct
22 Correct 74 ms 44112 KB Output is correct
23 Correct 56 ms 36176 KB Output is correct
24 Correct 84 ms 44372 KB Output is correct
25 Correct 53 ms 36176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 7 ms 29532 KB Output is correct
12 Correct 10 ms 37536 KB Output is correct
13 Correct 11 ms 29528 KB Output is correct
14 Correct 10 ms 37468 KB Output is correct
15 Correct 7 ms 29532 KB Output is correct
16 Correct 7 ms 29644 KB Output is correct
17 Correct 12 ms 37496 KB Output is correct
18 Correct 7 ms 29628 KB Output is correct
19 Correct 11 ms 37468 KB Output is correct
20 Correct 6 ms 29532 KB Output is correct
21 Correct 7 ms 29636 KB Output is correct
22 Correct 16 ms 37464 KB Output is correct
23 Correct 7 ms 29532 KB Output is correct
24 Correct 12 ms 37468 KB Output is correct
25 Correct 7 ms 29648 KB Output is correct
26 Correct 67 ms 35988 KB Output is correct
27 Correct 86 ms 44252 KB Output is correct
28 Correct 60 ms 36048 KB Output is correct
29 Correct 72 ms 44120 KB Output is correct
30 Correct 53 ms 36032 KB Output is correct
31 Correct 43 ms 37196 KB Output is correct
32 Correct 42 ms 37092 KB Output is correct
33 Correct 41 ms 37132 KB Output is correct
34 Correct 43 ms 37216 KB Output is correct
35 Correct 40 ms 36944 KB Output is correct
36 Correct 61 ms 44356 KB Output is correct
37 Correct 73 ms 44132 KB Output is correct
38 Correct 61 ms 44112 KB Output is correct
39 Correct 52 ms 44624 KB Output is correct
40 Correct 70 ms 44628 KB Output is correct
41 Correct 52 ms 35836 KB Output is correct
42 Correct 85 ms 44372 KB Output is correct
43 Correct 75 ms 44368 KB Output is correct
44 Correct 54 ms 35924 KB Output is correct
45 Correct 83 ms 44372 KB Output is correct
46 Correct 61 ms 35780 KB Output is correct
47 Correct 74 ms 44112 KB Output is correct
48 Correct 56 ms 36176 KB Output is correct
49 Correct 84 ms 44372 KB Output is correct
50 Correct 53 ms 36176 KB Output is correct
51 Correct 73 ms 37576 KB Output is correct
52 Correct 95 ms 45500 KB Output is correct
53 Correct 85 ms 37808 KB Output is correct
54 Correct 93 ms 45396 KB Output is correct
55 Correct 73 ms 37668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 29528 KB Output is correct
2 Correct 10 ms 35420 KB Output is correct
3 Correct 10 ms 37468 KB Output is correct
4 Correct 6 ms 29532 KB Output is correct
5 Correct 10 ms 37468 KB Output is correct
6 Correct 7 ms 29532 KB Output is correct
7 Correct 12 ms 37468 KB Output is correct
8 Correct 7 ms 29532 KB Output is correct
9 Correct 12 ms 35420 KB Output is correct
10 Correct 6 ms 29532 KB Output is correct
11 Correct 7 ms 29532 KB Output is correct
12 Correct 10 ms 37536 KB Output is correct
13 Correct 11 ms 29528 KB Output is correct
14 Correct 10 ms 37468 KB Output is correct
15 Correct 7 ms 29532 KB Output is correct
16 Correct 7 ms 29644 KB Output is correct
17 Correct 12 ms 37496 KB Output is correct
18 Correct 7 ms 29628 KB Output is correct
19 Correct 11 ms 37468 KB Output is correct
20 Correct 6 ms 29532 KB Output is correct
21 Correct 7 ms 29636 KB Output is correct
22 Correct 16 ms 37464 KB Output is correct
23 Correct 7 ms 29532 KB Output is correct
24 Correct 12 ms 37468 KB Output is correct
25 Correct 7 ms 29648 KB Output is correct
26 Correct 67 ms 35988 KB Output is correct
27 Correct 86 ms 44252 KB Output is correct
28 Correct 60 ms 36048 KB Output is correct
29 Correct 72 ms 44120 KB Output is correct
30 Correct 53 ms 36032 KB Output is correct
31 Correct 43 ms 37196 KB Output is correct
32 Correct 42 ms 37092 KB Output is correct
33 Correct 41 ms 37132 KB Output is correct
34 Correct 43 ms 37216 KB Output is correct
35 Correct 40 ms 36944 KB Output is correct
36 Correct 61 ms 44356 KB Output is correct
37 Correct 73 ms 44132 KB Output is correct
38 Correct 61 ms 44112 KB Output is correct
39 Correct 52 ms 44624 KB Output is correct
40 Correct 70 ms 44628 KB Output is correct
41 Correct 52 ms 35836 KB Output is correct
42 Correct 85 ms 44372 KB Output is correct
43 Correct 75 ms 44368 KB Output is correct
44 Correct 54 ms 35924 KB Output is correct
45 Correct 83 ms 44372 KB Output is correct
46 Correct 61 ms 35780 KB Output is correct
47 Correct 74 ms 44112 KB Output is correct
48 Correct 56 ms 36176 KB Output is correct
49 Correct 84 ms 44372 KB Output is correct
50 Correct 53 ms 36176 KB Output is correct
51 Correct 73 ms 37576 KB Output is correct
52 Correct 95 ms 45500 KB Output is correct
53 Correct 85 ms 37808 KB Output is correct
54 Correct 93 ms 45396 KB Output is correct
55 Correct 73 ms 37668 KB Output is correct
56 Execution timed out 1063 ms 92824 KB Time limit exceeded
57 Halted 0 ms 0 KB -