Submission #38854434


Source Code Expand

#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
typedef long long ll;
using namespace std;
const int mod = 998244353;
void amod(int &x, int y) {
	x = x + y >= mod ? x + y - mod : x + y;
}
void dmod(int &x, int y) {
	x = x - y < 0 ? x - y + mod : x - y;
}
int inc(int x, int y) {
	return x + y >= mod ? x + y - mod : x + y;
}
const int maxn = 5e5 + 5;
int n, a[maxn], b[maxn], f[maxn], pw[maxn];
vector<int> upd[maxn];
int main() {
#ifdef DEBUG
	freopen("1.in", "r", stdin);
#endif
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin >> n;
	pw[0] = 1;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> b[i];
		pw[i] = 2ll * pw[i - 1] % mod;
	}
	for(int i = 1, l = 0, r = 0; i <= n; i++) {
		while(b[l] < a[i]) {
			l++;
		}
		while(r + 1 <= n && a[r + 1] < b[i]) {
			r++;
		}
		upd[r].eb(l);
	}
	f[0] = 1;
	for(int i = 1; i <= n; i++) {
		f[i] = inc(f[i - 1], f[i - 1]);
		for(int j : upd[i]) {
			dmod(f[i], f[j - 1]);
		}
	}
	cout << f[n] << '\n';
	return 0;
}

Submission Info

Submission Time
Task C - First Come First Serve
User yanchengzhi
Language C++ (GCC 9.2.1)
Score 800
Code Size 1083 Byte
Status AC
Exec Time 114 ms
Memory 38788 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 2
AC × 33
Set Name Test Cases
Sample 01.txt, 02.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
Case Name Status Exec Time Memory
01.txt AC 15 ms 15248 KiB
02.txt AC 14 ms 15252 KiB
03.txt AC 15 ms 15300 KiB
04.txt AC 14 ms 15172 KiB
05.txt AC 14 ms 15264 KiB
06.txt AC 13 ms 15300 KiB
07.txt AC 14 ms 15356 KiB
08.txt AC 12 ms 15268 KiB
09.txt AC 16 ms 15280 KiB
10.txt AC 12 ms 15212 KiB
11.txt AC 16 ms 15276 KiB
12.txt AC 17 ms 15300 KiB
13.txt AC 16 ms 15380 KiB
14.txt AC 15 ms 15444 KiB
15.txt AC 17 ms 15636 KiB
16.txt AC 20 ms 16180 KiB
17.txt AC 27 ms 17168 KiB
18.txt AC 45 ms 19576 KiB
19.txt AC 93 ms 27696 KiB
20.txt AC 113 ms 31148 KiB
21.txt AC 114 ms 31180 KiB
22.txt AC 114 ms 31252 KiB
23.txt AC 106 ms 38788 KiB
24.txt AC 109 ms 34832 KiB
25.txt AC 110 ms 32640 KiB
26.txt AC 111 ms 30700 KiB
27.txt AC 107 ms 29160 KiB
28.txt AC 99 ms 27368 KiB
29.txt AC 96 ms 26624 KiB
30.txt AC 90 ms 26208 KiB
31.txt AC 86 ms 26072 KiB
32.txt AC 86 ms 25432 KiB
33.txt AC 86 ms 24648 KiB