Submission #38506361
Source Code Expand
// LUOGU_RID: 100996769
#include <bits/stdc++.h>
using namespace std;
namespace vbzIO{
char ibuf[(1 << 20) + 1], *iS, *iT;
#if ONLINE_JUDGE
#define gh() (iS == iT ? iT = (iS = ibuf) + fread(ibuf, 1, (1 << 20) + 1, stdin), (iS == iT ? EOF : *iS++) : *iS++)
#else
#define gh() getchar()
#endif
#define reg register
inline int read () {
reg char ch = gh();
reg long long x = 0;
reg char t = 0;
while (ch < '0' || ch > '9') t |= ch == '-', ch = gh();
while (ch >= '0' && ch <= '9') x = (x << 1) + (x << 3) + (ch ^ 48), ch = gh();
return t ? -x : x;
}
inline void write(int x) {
if (x < 0) {
x = ~(x - 1);
putchar('-');
}
if (x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
}
using vbzIO::read;
using vbzIO::write;
const int maxn = 2e5 + 200;
const int mod = 1e9 + 7;
struct node { int v, x, tx; } a[maxn];
int n, len, t[maxn], tmn[maxn], tmx[maxn], lp[maxn], rp[maxn], f[maxn], s[maxn];
vector<int> g[maxn];
#define lb(x) x & (-x)
void mdf1(int x, int y) { for (int i = x; i; i -= lb(i)) tmn[i] = min(tmn[i], y); }
void mdf2(int x, int y) { for (int i = x; i <= len; i += lb(i)) tmx[i] = max(tmx[i], y); }
int qry1(int x) { int res = len + 1; for (int i = x; i <= n; i += lb(i)) res = min(res, tmn[i]); return res; }
int qry2(int x) { int res = 0; for (int i = x; i; i -= lb(i)) res = max(res, tmx[i]); return res; }
int main() {
n = read();
for (int i = 1; i <= n; i++) {
a[i].x = read(), a[i].v = read();
t[++len] = a[i].x;
}
sort(t + 1, t + len + 1);
len = unique(t + 1, t + len + 1) - t - 1;
for (int i = 1; i <= n; i++)
a[i].tx = lower_bound(t + 1, t + len + 1, a[i].x) - t;
sort(a + 1, a + n + 1, [](const node &x, const node &y) { return x.v < y.v; });
memset(tmn, 0x3f, sizeof(tmn));
for (int i = 1; i <= n; i++)
mdf1(a[i].tx, i), lp[i] = qry1(a[i].tx);
for (int i = n; i; i--)
mdf2(a[i].tx, i), rp[i] = qry2(a[i].tx);
for (int i = 1; i <= n; i++) g[rp[i]].push_back(lp[i]);
for (int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
f[0] = s[0] = 1;
// for (int i = 0; i <= n; i++) s[0] = 1;
for (int i = 1; i <= n; i++) {
s[i] = s[i - 1];
for (int j : g[i])
(f[i] += (s[i] - (j >= 2 ? s[j - 2] : 0) + mod) % mod) %= mod,
s[i] = (s[i - 1] + f[i]) % mod;
}
write(f[n]);
return 0;
}
/*
3
2 5
6 1
3 7
*/
Submission Info
Submission Time
2023-01-31 21:05:20+0900
Task
E - Mr.Aoki Incubator
User
luogu_bot2
Language
C++ (GCC 9.2.1)
Score
1200
Code Size
2372 Byte
Status
AC
Exec Time
90 ms
Memory
23284 KiB
Compile Error
./Main.cpp: In function ‘int vbzIO::read()’:
./Main.cpp:14:12: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
14 | reg char ch = gh();
| ^~
./Main.cpp:15:17: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
15 | reg long long x = 0;
| ^
./Main.cpp:16:12: warning: ISO C++17 does not allow ‘register’ storage class specifier [-Wregister]
16 | reg char t = 0;
| ^
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
65 ms
16980 KiB
02.txt
AC
63 ms
16864 KiB
03.txt
AC
87 ms
16628 KiB
04.txt
AC
68 ms
16732 KiB
05.txt
AC
65 ms
16680 KiB
06.txt
AC
82 ms
16780 KiB
07.txt
AC
62 ms
16816 KiB
08.txt
AC
63 ms
16836 KiB
09.txt
AC
88 ms
23232 KiB
10.txt
AC
47 ms
16796 KiB
11.txt
AC
53 ms
21692 KiB
12.txt
AC
90 ms
22416 KiB
13.txt
AC
57 ms
22976 KiB
14.txt
AC
57 ms
22940 KiB
15.txt
AC
86 ms
22980 KiB
16.txt
AC
55 ms
22940 KiB
17.txt
AC
58 ms
23284 KiB
18.txt
AC
87 ms
23192 KiB
19.txt
AC
56 ms
23172 KiB
20.txt
AC
56 ms
23192 KiB
21.txt
AC
88 ms
19552 KiB
22.txt
AC
61 ms
19440 KiB
23.txt
AC
60 ms
19596 KiB
24.txt
AC
90 ms
19480 KiB
25.txt
AC
51 ms
17296 KiB
26.txt
AC
49 ms
17372 KiB
27.txt
AC
81 ms
17960 KiB
28.txt
AC
49 ms
17100 KiB
29.txt
AC
52 ms
19984 KiB
30.txt
AC
86 ms
21168 KiB
31.txt
AC
9 ms
8888 KiB
32.txt
AC
9 ms
8944 KiB
33.txt
AC
9 ms
8948 KiB
34.txt
AC
8 ms
8968 KiB
s1.txt
AC
10 ms
9000 KiB
s2.txt
AC
10 ms
8860 KiB