Submission #447954

# Submission time Handle Problem Language Result Execution time Memory
447954 2021-07-28T09:19:54 Z parsabahrami Fish (IOI08_fish) C++17
0 / 100
420 ms 20872 KB
/* I do it for the glory */
#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
#define lc id << 1
#define rc lc | 1

const int N = 5e5 + 10;
int lst[N], seg[N << 2], ord[N], A[N], g[N], k, mod, n;

void upd(int p, int id = 1, int l = 1, int r = n + 1) { 
    if (r - l < 2) { seg[id] = (seg[id] + 1) % mod; return; }
    int md = (l + r) >> 1;
    p < md ? upd(p, lc, l, md) : upd(p, rc, md, r);
    seg[id] = 1ll * seg[lc] * seg[rc] % mod;
}

int get(int ql, int qr, int id = 1, int l = 1, int r = n + 1) {
    if (qr <= l || r <= ql) return 1;
    if (ql <= l && r <= qr) return seg[id];
    int md = (l + r) >> 1;
    return 1ll * get(ql, qr, lc, l, md) * get(ql, qr, rc, md, r) % mod;
}

int main() {
    scanf("%d%d%d", &n, &k, &mod);
    for (int i = 1; i <= n; i++) {
        scanf("%d%d", &A[i], &g[i]), ord[i] = i;
    }
    sort(ord + 1, ord + n + 1, [&] (int i, int j) { return A[i] < A[j]; });
    for (int _ = n; _; _--) {
        int i = ord[_]; 
        if (!lst[g[i]]) lst[g[i]] = _;
    }
    int ret = 0;
    fill(seg, seg + N * 4, 1);
    for (int j = 1, pt = 0; j <= n; j++) {
        int i = ord[j];
        while (A[ord[pt + 1]] * 2 <= A[i]) pt++, upd(lst[g[ord[pt]]]);
        if (j != lst[g[i]]) continue;
        ret = (ret + get(1, j + 1)) % mod;
    }
    printf("%d\n", ret);
    return 0;
}

Compilation message

fish.cpp: In function 'int main()':
fish.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |     scanf("%d%d%d", &n, &k, &mod);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%d%d", &A[i], &g[i]), ord[i] = i;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8072 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8140 KB Output is correct
2 Incorrect 6 ms 8160 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 8140 KB Output is correct
2 Incorrect 248 ms 19976 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 8140 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 10472 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 8140 KB Output is correct
2 Correct 9 ms 8140 KB Output is correct
3 Incorrect 8 ms 8192 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 151 ms 11652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 251 ms 13956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 135 ms 11704 KB Output is correct
2 Incorrect 296 ms 20872 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 303 ms 13452 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 301 ms 14060 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 208 ms 13016 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 334 ms 13996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 338 ms 13992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 420 ms 14644 KB Output isn't correct
2 Halted 0 ms 0 KB -