Submission #69481778
Source Code Expand
/* Code By WCM */
/*
Date:
大致思路:
复杂度:
期望得分:
*/
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <vector>
#include <queue>
#define pii pair<int,int>
#define F first
#define S second
using namespace std;
inline int read();
void write(int);
void writeln(int);
const int N = 1e6 + 5, inf = 1e9;
int n, Q, minn[N << 2], maxx[N << 2];
#define lson (u << 1)
#define rson (u << 1 | 1)
void pushup(int u) {
minn[u] = min(minn[lson], minn[rson]), maxx[u] = max(maxx[lson], maxx[rson]);
}
void build(int u, int l, int r) {
if(l == r) { minn[u] = inf, maxx[u] = 0; return ; }
int mid = l + r >> 1;
build(lson, l, mid), build(rson, mid + 1, r);
pushup(u);
}
void update(int u, int l, int r, int p, int v) {
if(l == r) { minn[u] = maxx[u] = v; return ; }
int mid = l + r >> 1;
if(p <= mid) update(lson, l, mid, p, v);
else update(rson, mid + 1, r, p, v);
pushup(u);
}
pii query(int u, int l, int r, int ql, int qr) {
if(ql > r || qr < l) return {inf, 0};
if(ql <= l && r <= qr) return {minn[u], maxx[u]};
int mid = l + r >> 1;
pii L = query(lson, l, mid, ql, qr), R = query(rson, mid + 1, r, ql, qr);
return {min(L.F, R.F), max(L.S, R.S)};
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
n = read(), Q = read();
build(1, 1, n);
while(Q--) {
int a = read(), b = read();
if(a > b) swap(a, b);
int l = a + 1, r = b - 1;
if(l > r) puts("Yes"), update(1, 1, n, a, b), update(1, 1, n, b, a);
else {
pii res = query(1, 1, n, l, r);
int mv = res.F, mx = res.S;
if(mv == inf && mx == 0) puts("Yes"), update(1, 1, n, a, b), update(1, 1, n, b, a);
else {
if(mv < a || mx > b) puts("No");
else puts("Yes"), update(1, 1, n, a, b), update(1, 1, n, b, a);
}
}
}
// printf("\nThe time used: ");
// printf("%.2lfs",(double)clock()/CLOCKS_PER_SEC);
return 0;
}
inline int read() {
int res = 0, f = 1;
char ch = getchar();
while( !(ch >= '0' && ch <= '9') ) {
if(ch == '-') f = -1;
ch = getchar();
}
while(ch >= '0' && ch <= '9') {
res = (res << 1) + (res << 3) + (ch ^ 48);
ch = getchar();
}
return res * f;
}
void write(int x) {
static int sta[35];
int top = 0;
do {
sta[top++] = x % 10;
x /= 10;
} while(x);
while(top) putchar(sta[--top] ^ 48);
}
void writeln(int x) {
write(x);
putchar('\n');
}
Submission Info
Submission Time
2025-09-20 21:35:05+0900
Task
F - Adding Chords
User
WZwangchongming
Language
C++ 20 (gcc 12.2)
Score
525
Code Size
2508 Byte
Status
AC
Exec Time
339 ms
Memory
20044 KiB
Compile Error
Main.cpp: In function ‘void build(int, int, int)’:
Main.cpp:36:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
36 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function ‘void update(int, int, int, int, int)’:
Main.cpp:42:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
42 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function ‘std::pair<int, int> query(int, int, int, int, int)’:
Main.cpp:50:21: warning: suggest parentheses around ‘+’ inside ‘>>’ [-Wparentheses]
50 | int mid = l + r >> 1;
| ~~^~~
Judge Result
Set Name
Sample
All
Score / Max Score
0 / 0
525 / 525
Status
Set Name
Test Cases
Sample
sample_01.txt, sample_02.txt
All
min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, sample_01.txt, sample_02.txt
Case Name
Status
Exec Time
Memory
min.txt
AC
1 ms
3576 KiB
random_01.txt
AC
203 ms
19832 KiB
random_02.txt
AC
66 ms
19904 KiB
random_03.txt
AC
197 ms
19960 KiB
random_04.txt
AC
138 ms
19892 KiB
random_05.txt
AC
200 ms
19896 KiB
random_06.txt
AC
121 ms
19860 KiB
random_07.txt
AC
201 ms
19828 KiB
random_08.txt
AC
159 ms
19836 KiB
random_09.txt
AC
113 ms
19848 KiB
random_10.txt
AC
16 ms
19904 KiB
random_11.txt
AC
109 ms
19964 KiB
random_12.txt
AC
59 ms
19904 KiB
random_13.txt
AC
193 ms
19832 KiB
random_14.txt
AC
156 ms
19856 KiB
random_15.txt
AC
189 ms
19768 KiB
random_16.txt
AC
116 ms
11652 KiB
random_17.txt
AC
116 ms
19836 KiB
random_18.txt
AC
116 ms
19832 KiB
random_19.txt
AC
198 ms
19836 KiB
random_20.txt
AC
176 ms
19764 KiB
random_21.txt
AC
132 ms
19848 KiB
random_22.txt
AC
173 ms
19852 KiB
random_23.txt
AC
111 ms
19968 KiB
random_24.txt
AC
176 ms
19904 KiB
random_25.txt
AC
112 ms
19884 KiB
random_26.txt
AC
339 ms
20044 KiB
random_27.txt
AC
332 ms
19892 KiB
random_28.txt
AC
104 ms
19832 KiB
random_29.txt
AC
104 ms
19852 KiB
random_30.txt
AC
198 ms
19840 KiB
random_31.txt
AC
200 ms
19904 KiB
sample_01.txt
AC
1 ms
3520 KiB
sample_02.txt
AC
12 ms
19896 KiB