Submission #520176

# Submission time Handle Problem Language Result Execution time Memory
520176 2022-01-28T16:30:37 Z qwerasdfzxcl 허수아비 (JOI14_scarecrows) C++14
100 / 100
579 ms 13992 KB
#include <bits/stdc++.h>

typedef long long ll;
using namespace std;
const int INF = 1e9;
struct Seg{
    int tree[400400], sz;
    void init(int n){
        sz = n;
        fill(tree, tree+sz*2, INF);
    }
    void update(int p, int x){
        for (tree[p+=sz]=x;p>1;p>>=1) tree[p>>1] = min(tree[p], tree[p^1]);
    }
    int query(int l, int r){
        int ret = INF;
        for (l+=sz, r+=sz;l<r;l>>=1, r>>=1){
            if (l&1) ret = min(ret, tree[l++]);
            if (r&1) ret = min(ret, tree[--r]);
        }
        return ret;
    }
}tree1, tree2;

pair<int, int> a[200200];
ll ans;

void compress(vector<int> &a){
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
}

int getidx(int x, vector<int> &a){
    return lower_bound(a.begin(), a.end(), x) - a.begin();
}

void dnc(int l, int r){
    if (l==r) return;
    int m = (l+r)>>1;

    vector<pair<int, int>> V;
    for (int i=l;i<=r;i++) V.emplace_back(-a[i].second, i);
    sort(V.begin(), V.end());

    tree1.init(m-l+1);
    tree2.init(r-l+1);

    vector<int> st;
    int cnt = 0;

    for (auto &p:V){
        int i = p.second;
        if (i<=m){
            int L = -tree1.query(i-l, m-l+1);
            if (L==-INF) L = 0;
            int mn = tree2.query(L, cnt+1);
            ans += st.end() - lower_bound(st.begin(), st.end(), mn);

            tree1.update(i-l, -cnt);
        }
        else{
            tree2.update(cnt, i);
            while(!st.empty() && st.back() > i) st.pop_back();
            st.push_back(i);
        }
        cnt++;
    }

    dnc(l, m);
    dnc(m+1, r);
}

int main(){
    int n;
    scanf("%d", &n);
    vector<int> X, Y;
    X.push_back(-INF);
    Y.push_back(-INF);

    for (int i=1;i<=n;i++){
        scanf("%d %d", &a[i].first, &a[i].second);
        X.push_back(a[i].first);
        Y.push_back(a[i].second);
    }

    compress(X); compress(Y);
    assert((int)X.size()==n+1);
    assert((int)Y.size()==n+1);

    for (int i=1;i<=n;i++){
        a[i].first = getidx(a[i].first, X);
        a[i].second = getidx(a[i].second, Y);
    }

    sort(a+1, a+n+1);

    dnc(1, n);
    printf("%lld\n", ans);
    return 0;
}

Compilation message

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
scarecrows.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         scanf("%d %d", &a[i].first, &a[i].second);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 656 KB Output is correct
2 Correct 10 ms 588 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 6 ms 688 KB Output is correct
5 Correct 11 ms 588 KB Output is correct
6 Correct 9 ms 588 KB Output is correct
7 Correct 9 ms 588 KB Output is correct
8 Correct 7 ms 588 KB Output is correct
9 Correct 9 ms 684 KB Output is correct
10 Correct 10 ms 588 KB Output is correct
11 Correct 10 ms 588 KB Output is correct
12 Correct 7 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 403 ms 12612 KB Output is correct
2 Correct 579 ms 13420 KB Output is correct
3 Correct 467 ms 13816 KB Output is correct
4 Correct 330 ms 13340 KB Output is correct
5 Correct 489 ms 13396 KB Output is correct
6 Correct 528 ms 13324 KB Output is correct
7 Correct 548 ms 13348 KB Output is correct
8 Correct 557 ms 13572 KB Output is correct
9 Correct 403 ms 13948 KB Output is correct
10 Correct 541 ms 13520 KB Output is correct
11 Correct 556 ms 13352 KB Output is correct
12 Correct 567 ms 13508 KB Output is correct
13 Correct 557 ms 13484 KB Output is correct
14 Correct 397 ms 13992 KB Output is correct
15 Correct 560 ms 13436 KB Output is correct
16 Correct 564 ms 13520 KB Output is correct
17 Correct 326 ms 9016 KB Output is correct
18 Correct 553 ms 13352 KB Output is correct
19 Correct 571 ms 13440 KB Output is correct
20 Correct 558 ms 13400 KB Output is correct