답안 #48273

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
48273 2018-05-11T09:56:13 Z choikiwon 허수아비 (JOI14_scarecrows) C++17
0 / 100
355 ms 77052 KB
#include<bits/stdc++.h>
using namespace std;

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

const int MN = 200010;

int N;
pii P[MN];
vector<pii> ord;

struct BIT {
    vector<vector<pii> > tree;
    void init() {
        tree = vector<vector<pii> >(4 * N);
    }
    void upd(int a, int b, pii v, int l, int r, int n) {
        if(b < l || r < a) return;
        while(tree[n].size() && tree[n].back().second >= v.second) tree[n].pop_back();
        tree[n].push_back(v);
        if(a <= l && r <= b) return;
        int m = (l + r)>>1;
        upd(a, b, v, l, m, 2*n);
        upd(a, b, v, m + 1, r, 2*n + 1);
    }
    int quer(int ly, int ry, int x, int l, int r, int n) {
        if(l > r) return 0;

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

            if(tree[n][m].first > x && ry > tree[n][m].second && tree[n][m].second > ly) {
                p = m;
                s = m + 1;
            }
            else e = m - 1;
        }

        if(l == r) return p + 1;
        if(p != -1) {
            x = max(x, tree[n][0].first);
            ry = min(ry, tree[n][0].second);
        }
        int m = (l + r)>>1;
        int R = quer(ly, ry, x, m + 1, r, 2*n + 1);
        return R + p + 1;
    }
} bit;

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

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

    sort(P, P + N);

    ll ans = 0;
    bit.init();
    for(int i = N - 1; i >= 0; i--) {
        ans += bit.quer(P[i].second, 1e9, -1, 0, N - 1, 1);
        bit.upd(P[i].second, N - 1, P[i], 0, N - 1, 1);
    }

    printf("%lld", ans);
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
scarecrows.cpp:56: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 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 8 ms 2020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 355 ms 77052 KB Output isn't correct
2 Halted 0 ms 0 KB -