답안 #55410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
55410 2018-07-07T08:09:49 Z 내가진짜뚜룹뚭스(#2073) Employment (JOI16_employment) C++11
10 / 100
5000 ms 4228 KB
#include <bits/stdc++.h>

using namespace std;

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

int n, m;
int SZ = 440;
vector<pii> ma[510];
vector<int> vec[510];

int done[510];
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;
             ~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 15 ms 436 KB Output is correct
5 Correct 7 ms 492 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 25 ms 568 KB Output is correct
8 Correct 26 ms 620 KB Output is correct
9 Correct 30 ms 712 KB Output is correct
10 Correct 39 ms 712 KB Output is correct
11 Correct 39 ms 712 KB Output is correct
12 Correct 42 ms 712 KB Output is correct
13 Correct 38 ms 712 KB Output is correct
14 Correct 45 ms 712 KB Output is correct
15 Correct 40 ms 712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 712 KB Output is correct
2 Correct 5 ms 712 KB Output is correct
3 Correct 6 ms 764 KB Output is correct
4 Correct 55 ms 868 KB Output is correct
5 Correct 174 ms 1308 KB Output is correct
6 Correct 364 ms 1564 KB Output is correct
7 Correct 938 ms 2224 KB Output is correct
8 Correct 1464 ms 2620 KB Output is correct
9 Correct 3470 ms 3580 KB Output is correct
10 Correct 3157 ms 4116 KB Output is correct
11 Execution timed out 5025 ms 4228 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 15 ms 436 KB Output is correct
5 Correct 7 ms 492 KB Output is correct
6 Correct 8 ms 512 KB Output is correct
7 Correct 25 ms 568 KB Output is correct
8 Correct 26 ms 620 KB Output is correct
9 Correct 30 ms 712 KB Output is correct
10 Correct 39 ms 712 KB Output is correct
11 Correct 39 ms 712 KB Output is correct
12 Correct 42 ms 712 KB Output is correct
13 Correct 38 ms 712 KB Output is correct
14 Correct 45 ms 712 KB Output is correct
15 Correct 40 ms 712 KB Output is correct
16 Correct 5 ms 712 KB Output is correct
17 Correct 5 ms 712 KB Output is correct
18 Correct 6 ms 764 KB Output is correct
19 Correct 55 ms 868 KB Output is correct
20 Correct 174 ms 1308 KB Output is correct
21 Correct 364 ms 1564 KB Output is correct
22 Correct 938 ms 2224 KB Output is correct
23 Correct 1464 ms 2620 KB Output is correct
24 Correct 3470 ms 3580 KB Output is correct
25 Correct 3157 ms 4116 KB Output is correct
26 Execution timed out 5025 ms 4228 KB Time limit exceeded
27 Halted 0 ms 0 KB -