Submission #69493262
Source Code Expand
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ll long long
class SegmentTreeMx{
private:
std::vector<int> aint;
int n;
int join(int x, int y) {
return max(x, y);
}
void _update(int node, int from, int to, int x, int val) {
if(from < to) {
int mid = (from + to) / 2;
if(x <= mid)
_update(node * 2, from, mid, x, val);
else
_update(node * 2 + 1, mid + 1, to, x, val);
aint[node] = join(aint[node * 2], aint[node * 2 + 1]);
} else
aint[node] = val;
}
int _query(int node, int from, int to, int x, int y) {
if(from == x && to == y) {
return aint[node];
} else {
int mid = (from + to) / 2;
if(x <= mid && y <= mid)
return _query(node * 2, from, mid, x, y);
else if(mid + 1 <= x && mid + 1 <= y)
return _query(node * 2 + 1, mid + 1, to, x, y);
else
return join(_query(node * 2, from, mid, x, mid),
_query(node * 2 + 1, mid + 1, to, mid + 1, y));
}
}
void _print(int node, int from, int to) {
if(from < to) {
int mid = (from + to) / 2;
_print(node * 2, from, mid);
_print(node * 2 + 1, mid + 1, to);
} else
std::cout << aint[node] << " ";
}
public:
SegmentTreeMx(int n_) {
n = n_;
aint.resize(1 + 4 * n);
}
void update(int x, int val) {
_update(1, 1, n, x, val);
}
int query(int x, int y) {
return _query(1, 1, n, x, y);
}
void print() {
std::cout << "Print array\n";
_print(1, 1, n);
std::cout << '\n';
}
};
class SegmentTreeMn{
private:
std::vector<int> aint;
int n;
int join(int x, int y) {
return min(x, y);
}
void _update(int node, int from, int to, int x, int val) {
if(from < to) {
int mid = (from + to) / 2;
if(x <= mid)
_update(node * 2, from, mid, x, val);
else
_update(node * 2 + 1, mid + 1, to, x, val);
aint[node] = join(aint[node * 2], aint[node * 2 + 1]);
} else
aint[node] = val;
}
int _query(int node, int from, int to, int x, int y) {
if(from == x && to == y) {
return aint[node];
} else {
int mid = (from + to) / 2;
if(x <= mid && y <= mid)
return _query(node * 2, from, mid, x, y);
else if(mid + 1 <= x && mid + 1 <= y)
return _query(node * 2 + 1, mid + 1, to, x, y);
else
return join(_query(node * 2, from, mid, x, mid),
_query(node * 2 + 1, mid + 1, to, mid + 1, y));
}
}
void _print(int node, int from, int to) {
if(from < to) {
int mid = (from + to) / 2;
_print(node * 2, from, mid);
_print(node * 2 + 1, mid + 1, to);
} else
std::cout << aint[node] << " ";
}
public:
SegmentTreeMn(int n_) {
n = n_;
aint.resize(1 + 4 * n);
}
void update(int x, int val) {
_update(1, 1, n, x, val);
}
int query(int x, int y) {
return _query(1, 1, n, x, y);
}
void print() {
std::cout << "Print array\n";
_print(1, 1, n);
std::cout << '\n';
}
};
int main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, q;
cin>>n>>q;
SegmentTreeMx st1(n+5);
SegmentTreeMn st2(n+5);
int nxt[n+5], prev[n+5];
for(int i=1; i<=n; i++){
st1.update(i, i);
st2.update(i, i);
}
while(q--){
int l, r;
cin>>l>>r;
if(st1.query(l, r) > r || st2.query(l, r) < l) cout<<"No\n";
else{
cout<<"Yes\n";
nxt[l] = r;
prev[r] = l;
st1.update(l, r);
st2.update(r, l);
}
}
return 0;
}
Submission Info
Submission Time
2025-09-20 22:03:41+0900
Task
F - Adding Chords
User
takeonicky
Language
C++ 20 (gcc 12.2)
Score
525
Code Size
3703 Byte
Status
AC
Exec Time
438 ms
Memory
42260 KiB
Compile Error
Main.cpp: In function ‘int main()’:
Main.cpp:146:13: warning: variable ‘nxt’ set but not used [-Wunused-but-set-variable]
146 | int nxt[n+5], prev[n+5];
| ^~~
Main.cpp:146:23: warning: variable ‘prev’ set but not used [-Wunused-but-set-variable]
146 | int nxt[n+5], prev[n+5];
| ^~~~
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
3516 KiB
random_01.txt
AC
277 ms
42184 KiB
random_02.txt
AC
191 ms
42256 KiB
random_03.txt
AC
229 ms
31992 KiB
random_04.txt
AC
211 ms
34512 KiB
random_05.txt
AC
281 ms
42092 KiB
random_06.txt
AC
225 ms
42024 KiB
random_07.txt
AC
272 ms
41568 KiB
random_08.txt
AC
245 ms
41568 KiB
random_09.txt
AC
271 ms
42124 KiB
random_10.txt
AC
163 ms
42144 KiB
random_11.txt
AC
246 ms
36288 KiB
random_12.txt
AC
163 ms
30240 KiB
random_13.txt
AC
322 ms
42128 KiB
random_14.txt
AC
286 ms
42096 KiB
random_15.txt
AC
307 ms
38556 KiB
random_16.txt
AC
185 ms
22336 KiB
random_17.txt
AC
284 ms
42092 KiB
random_18.txt
AC
283 ms
42144 KiB
random_19.txt
AC
355 ms
42116 KiB
random_20.txt
AC
332 ms
42116 KiB
random_21.txt
AC
268 ms
42160 KiB
random_22.txt
AC
330 ms
42116 KiB
random_23.txt
AC
254 ms
42148 KiB
random_24.txt
AC
333 ms
42140 KiB
random_25.txt
AC
251 ms
42256 KiB
random_26.txt
AC
438 ms
42072 KiB
random_27.txt
AC
438 ms
42116 KiB
random_28.txt
AC
275 ms
42260 KiB
random_29.txt
AC
254 ms
42096 KiB
random_30.txt
AC
297 ms
42124 KiB
random_31.txt
AC
298 ms
42116 KiB
sample_01.txt
AC
1 ms
3432 KiB
sample_02.txt
AC
157 ms
42076 KiB