Submission #79810

# Submission time Handle Problem Language Result Execution time Memory
79810 2018-10-16T14:07:16 Z aquablitz11 trapezoid (balkan11_trapezoid) C++14
100 / 100
439 ms 33692 KB
#include <bits/stdc++.h>
using namespace std;
 
using pii = pair<int, int>;
using piipii = pair<pii, pii>;
using pipii = pair<int, pii>;
#define all(x) x.begin(), x.end()
#define mp make_pair
#define F first
#define S second
 
pii comb(pii a, pii b) {
    if (a.F == b.F)
        return pii(a.F, (a.S+b.S)%30013);
    else
        return max(a, b);
}
 
const int N = 1<<17;
int n;
piipii A[N];
 
struct data {
    vector<int> key;
    vector<pii> val;
    data() {}
} ft[N];
vector<pii> coord;

pii queryft(vector<pii> &ft, int i) {
    pii ans(0, 0);
    for (; i < ft.size(); i += i&-i)
        ans = comb(ans, ft[i]);
    return ans;
}

void updateft(vector<pii> &ft, int i, pii v) {
    for (; i > 0; i -= i&-i)
        ft[i] = comb(ft[i], v);
}

pii query(int x, int y) {
    pii ans(0, 0);
    for (; x <= n; x += x&-x) {
        int p = lower_bound(all(ft[x].key), y)-ft[x].key.begin()+1;
        ans = comb(ans, queryft(ft[x].val, p));
    }
    return ans;
}

void update(int x, int y, pii v) {
    for (; x > 0; x -= x&-x) {
        int p = lower_bound(all(ft[x].key), y)-ft[x].key.begin()+1;
        updateft(ft[x].val, p, v);
    }
}

void build() {
    for (int i = 1; i <= n; ++i) {
        for (int j = i-(i&-i); j > 0; j -= j&-j)
            ft[j].key.push_back(A[i-1].F.S);
        for (int j = i; j <= n; j += j&-j)
            ft[j].key.push_back(A[i-1].F.S);
    }
    for (int i = 1; i <= n; ++i) {
        sort(all(ft[i].key));
        ft[i].val.resize(ft[i].key.size()+1, pii(0, 0));
        //printf("\n%d:", A[i].F.F);
        //for (auto x : ft[i].key) printf(" %d", x);
    }
}
 
int pos(int x) {
    return lower_bound(all(coord), pii(x, 0))-coord.begin()+1;
}
 
int main()
{
    scanf("%d", &n);
    for (int i = 0; i < n; ++i)
        scanf("%d%d%d%d", &A[i].F.F, &A[i].S.F, &A[i].F.S, &A[i].S.S);
    sort(A, A+n);
    for (int i = 0; i < n; ++i)
        coord.push_back(pii(A[i].F.F, i));
    sort(coord.begin(), coord.end());
    build();
 
    pii ans(0, 0);
    for (int i = n-1; i >= 0; --i) {
        int ul = A[i].F.F, dl = A[i].F.S;
        int ur = A[i].S.F, dr = A[i].S.S;
        pii best = query(pos(ur), dr);
        ++best.F;
        if (best == pii(1, 0))
            best.S = 1;
        ans = comb(ans, best);
        update(pos(ul), dl, best);
        //printf("ul=%d, dl=%d, update to %d %d\n", ul, dl, best.F, best.S);
    }
    printf("%d %d\n", ans.F, ans.S);
 
    return 0;
}

Compilation message

trapezoid.cpp: In function 'pii queryft(std::vector<std::pair<int, int> >&, int)':
trapezoid.cpp:32:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (; i < ft.size(); i += i&-i)
            ~~^~~~~~~~~~~
trapezoid.cpp: In function 'int main()':
trapezoid.cpp:79:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
trapezoid.cpp:81:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d%d", &A[i].F.F, &A[i].S.F, &A[i].F.S, &A[i].S.S);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 9 ms 6520 KB Output is correct
2 Correct 7 ms 6656 KB Output is correct
3 Correct 9 ms 6708 KB Output is correct
4 Correct 9 ms 6780 KB Output is correct
5 Correct 12 ms 7188 KB Output is correct
6 Correct 15 ms 7512 KB Output is correct
7 Correct 17 ms 7752 KB Output is correct
8 Correct 22 ms 8100 KB Output is correct
9 Correct 86 ms 9512 KB Output is correct
10 Correct 62 ms 12040 KB Output is correct
11 Correct 88 ms 13700 KB Output is correct
12 Correct 206 ms 20104 KB Output is correct
13 Correct 263 ms 22680 KB Output is correct
14 Correct 324 ms 25856 KB Output is correct
15 Correct 379 ms 26876 KB Output is correct
16 Correct 388 ms 28180 KB Output is correct
17 Correct 406 ms 29604 KB Output is correct
18 Correct 303 ms 30716 KB Output is correct
19 Correct 353 ms 32060 KB Output is correct
20 Correct 439 ms 33692 KB Output is correct