답안 #348952

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
348952 2021-01-16T07:22:30 Z parsabahrami 사다리꼴 (balkan11_trapezoid) C++17
100 / 100
168 ms 24152 KB
// Call my Name and Save me from The Dark
#include <bits/stdc++.h>
 
using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
 
#define SZ(x)                       (int) x.size()
#define F                           first
#define S                           second

const int N = 2e5 + 10, MOD = 30013;
int dp[N], pd[N], A[N], B[N], C[N], D[N], n; pii fen[N];
vector<int> vec[2][N], cl, cr;

pii operator+(pii x, pii y) {
    if (x.F > y.F) return x;
    if (x.F < y.F) return y;
    return {x.F, (x.S + y.S) % MOD};
}

void upd(int pos, pii x) {
    for (pos++; pos < N; pos += pos & -pos) fen[pos] = fen[pos] + x;
}

pii get(int pos) {
    pii ret = {0, 0};
    for (pos++; pos; pos -= pos & -pos) ret = ret + fen[pos];
    return ret;
}

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

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
        cl.push_back(A[i]); cl.push_back(B[i]);
        cr.push_back(C[i]); cr.push_back(D[i]);
    }
    sort(cl.begin(), cl.end());
    sort(cr.begin(), cr.end());
    cl.resize(unique(cl.begin(), cl.end()) - cl.begin());
    cr.resize(unique(cr.begin(), cr.end()) - cr.begin());
    for (int i = 1; i <= n; i++) {
        A[i] = id(A[i], cl);
        B[i] = id(B[i], cl);
        C[i] = id(C[i], cr);
        D[i] = id(D[i], cr);
        vec[0][A[i]].push_back(i);
        vec[1][B[i]].push_back(i);
    }
    for (int i = 0; i < SZ(cl); i++) {
        for (int &j : vec[0][i]) {
            tie(dp[j], pd[j]) = get(C[j] - 1);
            dp[j]++;
            if (!pd[j]) pd[j] = 1;
        }
        for (int &j : vec[1][i]) {
            upd(D[j], {dp[j], pd[j]});
        }
    }
    pii ret = {0, 0};
    for (int i = 1; i <= n; i++) {
        ret = ret + pii(dp[i], pd[i]);
    }
    printf("%d %d\n", ret.F, ret.S);
    return 0;
}

Compilation message

trapezoid.cpp: In function 'int main()':
trapezoid.cpp:38:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   38 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
trapezoid.cpp:40:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   40 |         scanf("%d%d%d%d", &A[i], &B[i], &C[i], &D[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 9836 KB Output is correct
2 Correct 7 ms 9836 KB Output is correct
3 Correct 8 ms 9836 KB Output is correct
4 Correct 8 ms 9964 KB Output is correct
5 Correct 9 ms 10092 KB Output is correct
6 Correct 11 ms 10240 KB Output is correct
7 Correct 12 ms 10348 KB Output is correct
8 Correct 14 ms 10476 KB Output is correct
9 Correct 21 ms 11264 KB Output is correct
10 Correct 35 ms 12648 KB Output is correct
11 Correct 42 ms 13416 KB Output is correct
12 Correct 84 ms 17000 KB Output is correct
13 Correct 102 ms 18528 KB Output is correct
14 Correct 134 ms 19928 KB Output is correct
15 Correct 135 ms 20568 KB Output is correct
16 Correct 144 ms 21352 KB Output is correct
17 Correct 150 ms 22128 KB Output is correct
18 Correct 142 ms 22744 KB Output is correct
19 Correct 150 ms 23404 KB Output is correct
20 Correct 168 ms 24152 KB Output is correct