답안 #51896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
51896 2018-06-22T13:14:41 Z someone_aa 사다리꼴 (balkan11_trapezoid) C++17
90 / 100
500 ms 34292 KB
#include <bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
using namespace std;
const int maxn = 100100;
const ll mod = 30013;
map<int, int> up, down;
int tree[2*4*maxn][2];
int upmax, downmax, n;
int dp[maxn];
int dpways[maxn];

struct trapez {
public:
    int a, b, c, d;
} arr[maxn];

struct node {
public:
    int maxm, cnt;
} bit[4*maxn];

node mergef(node a, node b) {
    if(a.maxm > b.maxm) return a;
    if(b.maxm > a.maxm) return b;
    a.cnt += b.cnt;
    if(a.cnt > mod)
        a.cnt -= mod;
    return a;
}

node query(int pos) {
    node temp;
    temp.cnt = temp.maxm = 0;
    for(; pos > 0; pos -= pos & (-pos)) {
        temp = mergef(temp, bit[pos]);
    }
    return temp;
}

void update(int pos, node value) {
    for(; pos <= downmax; pos += pos &(-pos)) {
        bit[pos] = mergef(bit[pos],value);
    }
}

vector<pair<int, bool> > events[2*maxn];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    scanf("%d", &n);
    for(int i=0;i<n;i++) {
        scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
        up[arr[i].a] = 1;
        up[arr[i].b] = 1;
        down[arr[i].c] = 1;
        down[arr[i].d] = 1;
    }

    upmax = downmax = 1;
    for(auto i:up) {
        up[i.first] = upmax++;
    }
    for(auto i:down) {
        down[i.first] = downmax++;
    }
    update(1, {0, 1});
    for(int i=0;i<n;i++) {
        arr[i].a = up[arr[i].a];
        arr[i].b = up[arr[i].b];
        arr[i].c = down[arr[i].c];
        arr[i].d = down[arr[i].d];

        events[arr[i].a].push_back(make_pair(i, true));
        events[arr[i].b].push_back(make_pair(i, false));
    }


    int result = 0;
    int ways = 0;
    for(int i=1;i<=upmax;i++) {
        for(auto j:events[i]) {
            if(j.second) {
                node temp = query(arr[j.first].c);
                dp[j.first] = temp.maxm + 1;
                dpways[j.first] = temp.cnt;
                if(dp[j.first] > result) {
                    result = dp[j.first];
                    ways = dpways[j.first];
                }
                else if(dp[j.first] == result) {
                    ways += dpways[j.first];
                    if(ways > mod) ways-=mod;
                }
            }
            else {
                update(arr[j.first].d, {dp[j.first], dpways[j.first]});
            }
        }
    }
    printf("%d %d", result, ways);
    return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
trapezoid.cpp:55:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d %d", &arr[i].a, &arr[i].b, &arr[i].c, &arr[i].d);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 4984 KB Output is correct
2 Correct 6 ms 5228 KB Output is correct
3 Correct 7 ms 5412 KB Output is correct
4 Correct 10 ms 5428 KB Output is correct
5 Correct 11 ms 5764 KB Output is correct
6 Correct 13 ms 6112 KB Output is correct
7 Correct 20 ms 6388 KB Output is correct
8 Correct 23 ms 6628 KB Output is correct
9 Correct 41 ms 8104 KB Output is correct
10 Correct 83 ms 11052 KB Output is correct
11 Correct 95 ms 12408 KB Output is correct
12 Correct 249 ms 19756 KB Output is correct
13 Correct 290 ms 22572 KB Output is correct
14 Correct 344 ms 25652 KB Output is correct
15 Correct 428 ms 26932 KB Output is correct
16 Correct 444 ms 28356 KB Output is correct
17 Execution timed out 578 ms 30012 KB Time limit exceeded
18 Correct 439 ms 31492 KB Output is correct
19 Correct 433 ms 32700 KB Output is correct
20 Execution timed out 523 ms 34292 KB Time limit exceeded