Submission #257932

# Submission time Handle Problem Language Result Execution time Memory
257932 2020-08-05T05:15:15 Z 문홍윤(#5065) Employment (JOI16_employment) C++17
100 / 100
4406 ms 8412 KB
#include <bits/stdc++.h>
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define svec(x) sort(x.begin(), x.end())
using namespace std;
typedef pair<int, int> pii;
const int BUC=1000;
const int MAXN=200000;
const int INF=1000000001;

int n, q, b;
int arr[MAXN+100000];
vector<pair<pii, pii> > vc[MAXN/BUC+10];
vector<pii> sor[MAXN/BUC+10];
int ch[MAXN+100000];

inline void get_vc(int bnum){
    vc[bnum].clear();
    vc[bnum].eb(mp(0, 0), mp(0, 0));
    for(int i=max(bnum*BUC-1, 0); i<=(bnum+1)*BUC; i++)ch[i]=0;
    int num=0;
    for(int i=0; i<sor[bnum].size(); i++){
        int nw=sor[bnum][i].S;
        ch[nw]=1;
        num++;
        if(nw>0&&ch[nw-1])num--;
        if(ch[nw+1])num--;
        if(i==sor[bnum].size()-1||sor[bnum][i+1].F!=sor[bnum][i].F){
            vc[bnum].eb(mp(sor[bnum][i].F, num), mp(ch[bnum*BUC], ch[(bnum+1)*BUC-1]));
        }
    }
}

inline pair<int, pii> query2(int bnum, int num){
    int tmp=lower_bound(vc[bnum].begin(), vc[bnum].end(), mp(mp(num, INF), mp(1, 1)))-vc[bnum].begin()-1;
    return mp(vc[bnum][tmp].F.S, vc[bnum][tmp].S);
}

inline int query(int num){
    int on=0, ans=0;
    for(int i=0; i<=b; i++){
        pair<int, pii> tmp=query2(i, num);
        ans+=tmp.F;
        if(on&&tmp.S.F)ans--;
        on=tmp.S.S;
    }
    return ans;
}

inline void update(int bnum, int a, int b){
    for(int i=0; i<sor[bnum].size(); i++){
        if(sor[bnum][i]==mp(arr[a], a)){
            sor[bnum][i]=mp(b, a);
            break;
        }
    }
    arr[a]=b;
    svec(sor[bnum]);
    get_vc(bnum);
}

int main(){
    scanf("%d %d", &n, &q);
    for(int i=0; i<n; i++){
        scanf("%d", &arr[i]);
        arr[i]=INF-arr[i];
    }
    b=(n-1)/BUC;
    for(int i=0; i<n; i++)sor[i/BUC].eb(arr[i], i);
    for(int i=0; i<=b; i++)svec(sor[i]);
    for(int i=0; i<=b; i++)get_vc(i);
    for(int i=1; i<=q; i++){
        int qnum;
        scanf("%d", &qnum);
        if(qnum==1){
            int a;
            scanf("%d", &a);
            printf("%d\n", query(INF-a));
        }
        else{
            int a, b;
            scanf("%d %d", &a, &b);
            a--;
            update(a/BUC, a, INF-b);
        }
    }
}

Compilation message

employment.cpp: In function 'void get_vc(int)':
employment.cpp:24:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<sor[bnum].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
employment.cpp:30:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(i==sor[bnum].size()-1||sor[bnum][i+1].F!=sor[bnum][i].F){
            ~^~~~~~~~~~~~~~~~~~~~
employment.cpp: In function 'void update(int, int, int)':
employment.cpp:53:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i=0; i<sor[bnum].size(); i++){
                  ~^~~~~~~~~~~~~~~~~
employment.cpp: In function 'int main()':
employment.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~~
employment.cpp:67:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &arr[i]);
         ~~~~~^~~~~~~~~~~~~~~
employment.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &qnum);
         ~~~~~^~~~~~~~~~~~~
employment.cpp:79:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a);
             ~~~~~^~~~~~~~~~
employment.cpp:84:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d", &a, &b);
             ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 16 ms 444 KB Output is correct
8 Correct 20 ms 444 KB Output is correct
9 Correct 19 ms 384 KB Output is correct
10 Correct 31 ms 384 KB Output is correct
11 Correct 28 ms 384 KB Output is correct
12 Correct 27 ms 384 KB Output is correct
13 Correct 29 ms 384 KB Output is correct
14 Correct 27 ms 384 KB Output is correct
15 Correct 28 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 31 ms 768 KB Output is correct
5 Correct 99 ms 1660 KB Output is correct
6 Correct 209 ms 1912 KB Output is correct
7 Correct 474 ms 3192 KB Output is correct
8 Correct 716 ms 3856 KB Output is correct
9 Correct 1715 ms 5472 KB Output is correct
10 Correct 1521 ms 7008 KB Output is correct
11 Correct 2454 ms 6880 KB Output is correct
12 Correct 2937 ms 8016 KB Output is correct
13 Correct 2944 ms 7892 KB Output is correct
14 Correct 2932 ms 7724 KB Output is correct
15 Correct 2912 ms 7724 KB Output is correct
16 Correct 3117 ms 7872 KB Output is correct
17 Correct 3089 ms 8244 KB Output is correct
18 Correct 3068 ms 8132 KB Output is correct
19 Correct 3148 ms 8360 KB Output is correct
20 Correct 3037 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 12 ms 384 KB Output is correct
5 Correct 6 ms 384 KB Output is correct
6 Correct 6 ms 384 KB Output is correct
7 Correct 16 ms 444 KB Output is correct
8 Correct 20 ms 444 KB Output is correct
9 Correct 19 ms 384 KB Output is correct
10 Correct 31 ms 384 KB Output is correct
11 Correct 28 ms 384 KB Output is correct
12 Correct 27 ms 384 KB Output is correct
13 Correct 29 ms 384 KB Output is correct
14 Correct 27 ms 384 KB Output is correct
15 Correct 28 ms 504 KB Output is correct
16 Correct 2 ms 384 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 3 ms 384 KB Output is correct
19 Correct 31 ms 768 KB Output is correct
20 Correct 99 ms 1660 KB Output is correct
21 Correct 209 ms 1912 KB Output is correct
22 Correct 474 ms 3192 KB Output is correct
23 Correct 716 ms 3856 KB Output is correct
24 Correct 1715 ms 5472 KB Output is correct
25 Correct 1521 ms 7008 KB Output is correct
26 Correct 2454 ms 6880 KB Output is correct
27 Correct 2937 ms 8016 KB Output is correct
28 Correct 2944 ms 7892 KB Output is correct
29 Correct 2932 ms 7724 KB Output is correct
30 Correct 2912 ms 7724 KB Output is correct
31 Correct 3117 ms 7872 KB Output is correct
32 Correct 3089 ms 8244 KB Output is correct
33 Correct 3068 ms 8132 KB Output is correct
34 Correct 3148 ms 8360 KB Output is correct
35 Correct 3037 ms 8412 KB Output is correct
36 Correct 32 ms 384 KB Output is correct
37 Correct 28 ms 384 KB Output is correct
38 Correct 35 ms 384 KB Output is correct
39 Correct 203 ms 1016 KB Output is correct
40 Correct 489 ms 1144 KB Output is correct
41 Correct 852 ms 1868 KB Output is correct
42 Correct 1126 ms 2808 KB Output is correct
43 Correct 1638 ms 3564 KB Output is correct
44 Correct 3151 ms 7020 KB Output is correct
45 Correct 2495 ms 5528 KB Output is correct
46 Correct 2922 ms 5924 KB Output is correct
47 Correct 4138 ms 7416 KB Output is correct
48 Correct 4286 ms 7256 KB Output is correct
49 Correct 4188 ms 7544 KB Output is correct
50 Correct 4175 ms 7232 KB Output is correct
51 Correct 4380 ms 7428 KB Output is correct
52 Correct 4406 ms 7460 KB Output is correct
53 Correct 4327 ms 7444 KB Output is correct
54 Correct 4385 ms 7432 KB Output is correct
55 Correct 4285 ms 7416 KB Output is correct