Submission #1768823
Source Code Expand
#include <cstdio> #include <cstring> #include <string> #include <cmath> #include <iostream> #include <algorithm> #include <map> #include <set> #include <queue> #include <vector> using namespace std; typedef long long ll; typedef unsigned int uint; typedef unsigned long long ull; typedef pair<int, int> PII; typedef vector<int> VI; #define fi first #define se second #define MP make_pair int read() { int v = 0, f = 1; char c = getchar(); while (c < 48 || 57 < c) {if (c == '-') f = -1; c = getchar();} while (48 <= c && c <= 57) v = (v << 3) + v + v + c - 48, c = getchar(); return v * f; } const int N = 2e5 + 10; const ll MOD = 1e9 + 7; const int INF = 2e9; ll f[N], g[N], mi[N]; int L[N], R[N], n, mx[N], mn[N]; PII a[N]; VI V[N]; ll query(int i, int j) { if (i == 0) return g[j]; else return (g[j] - g[i - 1] + MOD) % MOD; } int main() { n = read(); mi[0] = 1; for (int i = 1; i <= n; i++) mi[i] = mi[i - 1] * 2 % MOD; for (int i = 1; i <= n; i++) { int x = read(), v = read(); a[i] = MP(v, x); } sort(a + 1, a + n + 1); for (int i = 1; i <= n; i++) mx[i] = max(mx[i - 1], a[i].se); mn[n + 1] = INF; for (int i = n; i >= 1; i--) mn[i] = min(mn[i + 1], a[i].se); for (int i = 1; i <= n; i++) { int l = 1, r = i; while (l < r) { int mid = l + r >> 1; if (mx[mid] >= a[i].se) r = mid; else l = mid + 1; } L[i] = l; } for (int i = 1; i <= n; i++) { int l = i, r = n; while (l < r) { int mid = l + r + 1 >> 1; if (mn[mid] <= a[i].se) l = mid; else r = mid - 1; } R[i] = l; } for (int i = 1; i <= n; i++) V[R[i]].push_back(L[i]); f[0] = 1; g[0] = 1; for (int i = 1; i <= n; i++) { sort(V[i].begin(), V[i].end()); for (int j = 0; j < V[i].size(); j++) (f[i] += query(V[i][j] - 1, i - 1) * mi[V[i].size() - j - 1] % MOD) %= MOD; g[i] = (g[i - 1] + f[i]) % MOD; } printf("%lld\n", f[n]); }
Submission Info
Submission Time | |
---|---|
Task | E - Mr.Aoki Incubator |
User | Misaka10032 |
Language | C++14 (GCC 5.4.1) |
Score | 1200 |
Code Size | 2329 Byte |
Status | AC |
Exec Time | 81 ms |
Memory | 20608 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 1200 / 1200 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
Sample | s1.txt, s2.txt |
All | 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, 33.txt, 34.txt, s1.txt, s2.txt |
Case Name | Status | Exec Time | Memory |
---|---|---|---|
01.txt | AC | 68 ms | 13944 KB |
02.txt | AC | 67 ms | 13944 KB |
03.txt | AC | 67 ms | 13816 KB |
04.txt | AC | 68 ms | 13684 KB |
05.txt | AC | 66 ms | 13688 KB |
06.txt | AC | 66 ms | 13620 KB |
07.txt | AC | 67 ms | 13652 KB |
08.txt | AC | 66 ms | 13688 KB |
09.txt | AC | 79 ms | 20608 KB |
10.txt | AC | 53 ms | 13688 KB |
11.txt | AC | 65 ms | 18944 KB |
12.txt | AC | 78 ms | 19840 KB |
13.txt | AC | 67 ms | 20224 KB |
14.txt | AC | 67 ms | 20224 KB |
15.txt | AC | 79 ms | 20224 KB |
16.txt | AC | 67 ms | 20224 KB |
17.txt | AC | 67 ms | 20608 KB |
18.txt | AC | 79 ms | 20608 KB |
19.txt | AC | 67 ms | 20608 KB |
20.txt | AC | 67 ms | 20608 KB |
21.txt | AC | 81 ms | 16896 KB |
22.txt | AC | 71 ms | 16896 KB |
23.txt | AC | 71 ms | 16896 KB |
24.txt | AC | 81 ms | 16896 KB |
25.txt | AC | 65 ms | 14332 KB |
26.txt | AC | 61 ms | 14340 KB |
27.txt | AC | 75 ms | 14972 KB |
28.txt | AC | 62 ms | 14200 KB |
29.txt | AC | 66 ms | 17272 KB |
30.txt | AC | 78 ms | 18432 KB |
31.txt | AC | 4 ms | 12544 KB |
32.txt | AC | 4 ms | 12544 KB |
33.txt | AC | 4 ms | 12544 KB |
34.txt | AC | 4 ms | 12544 KB |
s1.txt | AC | 4 ms | 12544 KB |
s2.txt | AC | 4 ms | 12544 KB |