Submission #55400

# Submission time Handle Problem Language Result Execution time Memory
55400 2018-07-07T07:43:11 Z 내가진짜뚜룹뚭스(#2073) Employment (JOI16_employment) C++11
10 / 100
5000 ms 3380 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

int n, m;
int SZ = 200;
vector<pii> ma[1010];
vector<int> vec[1010];

int done[210];
int c;
void calc(int idx) {
    vector<pii> lis;
    int i;
    for (i=0;i<vec[idx].size();i++) {
        lis.push_back(pii(vec[idx][i],i));
    }
    sort(lis.begin(),lis.end());
    c = 0;
    for (i=0;i<vec[idx].size();i++) done[i] = 0;
    ma[idx].clear();
    for (i=(int)vec[idx].size()-1;i>=0;i--) {
        c++;
        int val = lis[i].first, loc = lis[i].second;
        done[loc] = 1;
        if (loc>0) {
            if (done[loc-1]) c--;
        }
        if (loc+1<lis.size()) {
            if (done[loc+1]) c--;
        }
        ma[idx].push_back(pii(val,c));
    }
    reverse(ma[idx].begin(),ma[idx].end());
    //for (pii &v : ma[idx]) {
    //    printf("%d, %d\n",v.first,v.second);
    //}
}

void upd(int idx, int val) {
    vec[idx/SZ][idx%SZ] = val;
    calc(idx/SZ);
}

int cal(int x) {
    int ed = 0, cnt = 0;
    int i;
    for (i=0;i<=(n-1)/SZ;i++) {
        if (ma[i].back().first<x) {
            ed = 0;
            continue;
        }
        //printf("%d, %d\n",(*lower_bound(ma[i].begin(),ma[i].end(),pii(x,-1))).first,(*lower_bound(ma[i].begin(),ma[i].end(),pii(x,-1))).second);
        cnt += (*lower_bound(ma[i].begin(),ma[i].end(),pii(x,-1))).second - ed*(vec[i][0]>=x);
        ed = (vec[i].back()>=x);
    }
    return cnt;
}

int main() {
    int i;

    scanf("%d%d",&n,&m);
    for (i=0;i<n;i++) {
        int a;
        scanf("%d",&a);
        vec[i/SZ].push_back(a);
    }
    for (i=0;i<=(n-1)/SZ;i++) calc(i);
    for (i=0;i<m;i++) {
        int t;
        scanf("%d",&t);
        if (t==1) {
            int x;
            scanf("%d",&x);
            printf("%d\n",cal(x));
        }
        else {
            int a, b;
            scanf("%d%d",&a,&b); --a;
            upd(a,b);
        }
    }

    return 0;
}

Compilation message

employment.cpp: In function 'void calc(int)':
employment.cpp:18:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<vec[idx].size();i++) {
              ~^~~~~~~~~~~~~~~~
employment.cpp:23:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i=0;i<vec[idx].size();i++) done[i] = 0;
              ~^~~~~~~~~~~~~~~~
employment.cpp:32:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (loc+1<lis.size()) {
             ~~~~~^~~~~~~~~~~
employment.cpp: In function 'int main()':
employment.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d",&n,&m);
     ~~~~~^~~~~~~~~~~~~~
employment.cpp:69:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&a);
         ~~~~~^~~~~~~~~
employment.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&t);
         ~~~~~^~~~~~~~~
employment.cpp:78:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&x);
             ~~~~~^~~~~~~~~
employment.cpp:83:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d%d",&a,&b); --a;
             ~~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 10 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 18 ms 596 KB Output is correct
8 Correct 13 ms 596 KB Output is correct
9 Correct 13 ms 596 KB Output is correct
10 Correct 17 ms 680 KB Output is correct
11 Correct 19 ms 680 KB Output is correct
12 Correct 18 ms 680 KB Output is correct
13 Correct 20 ms 680 KB Output is correct
14 Correct 20 ms 680 KB Output is correct
15 Correct 22 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 680 KB Output is correct
2 Correct 8 ms 680 KB Output is correct
3 Correct 6 ms 680 KB Output is correct
4 Correct 84 ms 900 KB Output is correct
5 Correct 313 ms 1284 KB Output is correct
6 Correct 640 ms 1684 KB Output is correct
7 Correct 1717 ms 2356 KB Output is correct
8 Correct 2473 ms 2668 KB Output is correct
9 Execution timed out 5051 ms 3380 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 3 ms 488 KB Output is correct
3 Correct 2 ms 488 KB Output is correct
4 Correct 10 ms 596 KB Output is correct
5 Correct 5 ms 596 KB Output is correct
6 Correct 4 ms 596 KB Output is correct
7 Correct 18 ms 596 KB Output is correct
8 Correct 13 ms 596 KB Output is correct
9 Correct 13 ms 596 KB Output is correct
10 Correct 17 ms 680 KB Output is correct
11 Correct 19 ms 680 KB Output is correct
12 Correct 18 ms 680 KB Output is correct
13 Correct 20 ms 680 KB Output is correct
14 Correct 20 ms 680 KB Output is correct
15 Correct 22 ms 680 KB Output is correct
16 Correct 4 ms 680 KB Output is correct
17 Correct 8 ms 680 KB Output is correct
18 Correct 6 ms 680 KB Output is correct
19 Correct 84 ms 900 KB Output is correct
20 Correct 313 ms 1284 KB Output is correct
21 Correct 640 ms 1684 KB Output is correct
22 Correct 1717 ms 2356 KB Output is correct
23 Correct 2473 ms 2668 KB Output is correct
24 Execution timed out 5051 ms 3380 KB Time limit exceeded
25 Halted 0 ms 0 KB -