답안 #48269

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48269 2018-05-11T07:44:45 Z choikiwon 허수아비 (JOI14_scarecrows) C++17
100 / 100
1257 ms 232632 KB
#include<bits/stdc++.h>
using namespace std;

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

const int MN = 200010;
const int SQ = 1000;
const int BS = (MN + SQ - 1) / SQ;

int N;
pii P[MN];
vector<pii> X, Y;
int invx[MN], invy[MN];
vector<pii> stk[BS];

int solve(int x) {
    int p = (P[x].second + SQ - 1) / SQ;

    vector<int> tmp;
    for(int i = min(N, p * SQ) - 1; i > P[x].second; i--) {
        if(invy[i] > x) {
            while(tmp.size() && tmp.back() >= invy[i]) tmp.pop_back();
            tmp.push_back(invy[i]);
        }
    }
    if(tmp.size() == 0) {
        return stk[p].size();
    }

    int s = 0, e = (int)stk[p].size() - 1, k = (int)stk[p].size();
    while(s <= e) {
        int m = (s + e)>>1;

        if(stk[p][m].first < tmp[0]) {
            k = m;
            e = m - 1;
        }
        else s = m + 1;
    }

    return (int)stk[p].size() - k + (int)tmp.size();
}

int main() {
    scanf("%d", &N);

    for(int i = 0; i < N; i++) {
        scanf("%d %d", &P[i].first, &P[i].second);
        X.push_back({ P[i].first, i });
        Y.push_back({ P[i].second, i });
    }
    sort(X.begin(), X.end());
    sort(Y.begin(), Y.end());
    for(int i = 0; i < N; i++) {
        P[ X[i].second ].first = i;
        P[ Y[i].second ].second = i;
    }
    for(int i = 0; i < N; i++) {
        invx[ P[i].first ] = P[i].second;
        invy[ P[i].second ] = P[i].first;
    }

    sort(P, P + N);

    ll ans = 0;
    for(int i = N - 1; i >= 0; i--) {
        ans += solve(i);

        for(int j = 0; j < BS; j++) {
            if(j * SQ > P[i].second) break;

            while(stk[j].size() && stk[j].back().second >= P[i].second) stk[j].pop_back();
            stk[j].push_back(P[i]);
        }
    }
    printf("%lld", ans);
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:46:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
scarecrows.cpp:49:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &P[i].first, &P[i].second);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 496 KB Output is correct
3 Correct 3 ms 560 KB Output is correct
4 Correct 2 ms 668 KB Output is correct
5 Correct 2 ms 668 KB Output is correct
6 Correct 3 ms 712 KB Output is correct
7 Correct 2 ms 716 KB Output is correct
8 Correct 2 ms 816 KB Output is correct
9 Correct 3 ms 816 KB Output is correct
10 Correct 2 ms 816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1132 KB Output is correct
2 Correct 22 ms 1244 KB Output is correct
3 Correct 11 ms 1348 KB Output is correct
4 Correct 11 ms 1356 KB Output is correct
5 Correct 14 ms 1604 KB Output is correct
6 Correct 21 ms 1604 KB Output is correct
7 Correct 25 ms 1672 KB Output is correct
8 Correct 7 ms 1900 KB Output is correct
9 Correct 16 ms 1916 KB Output is correct
10 Correct 21 ms 2040 KB Output is correct
11 Correct 22 ms 2072 KB Output is correct
12 Correct 11 ms 2172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 578 ms 147768 KB Output is correct
2 Correct 1235 ms 147768 KB Output is correct
3 Correct 588 ms 147768 KB Output is correct
4 Correct 453 ms 147768 KB Output is correct
5 Correct 595 ms 147768 KB Output is correct
6 Correct 1030 ms 147768 KB Output is correct
7 Correct 1204 ms 147768 KB Output is correct
8 Correct 1235 ms 147768 KB Output is correct
9 Correct 604 ms 222348 KB Output is correct
10 Correct 715 ms 222348 KB Output is correct
11 Correct 1066 ms 222348 KB Output is correct
12 Correct 1201 ms 222348 KB Output is correct
13 Correct 1257 ms 222348 KB Output is correct
14 Correct 596 ms 232632 KB Output is correct
15 Correct 1077 ms 232632 KB Output is correct
16 Correct 1243 ms 232632 KB Output is correct
17 Correct 610 ms 232632 KB Output is correct
18 Correct 1134 ms 232632 KB Output is correct
19 Correct 1068 ms 232632 KB Output is correct
20 Correct 1061 ms 232632 KB Output is correct