社区讨论
why RE (悬1关)
学术版参与者 2已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 4 条
- 当前快照
- 1 份
- 快照标识符
- @mi4krf4u
- 此快照首次捕获于
- 2025/11/18 20:53 3 个月前
- 此快照最后确认于
- 2025/11/20 04:04 3 个月前
rt, 帮忙看看。
题目:link
CPP#include <bits/stdc++.h>
#define I ios::sync_with_stdio(false);cin.tie(0)
using ll = long long;
using namespace std;
int read () {
int x = 0, f = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') f = -f;
ch = getchar();
}
while(isdigit(ch)) {
x = x * 10 + ch - '0';
ch = getchar();
}
return x * f;
}
void write (int x) {
if(x < 0) {
putchar('-');
x = -x;
}
stack <int> s;
while(x) {
s.push(x % 10);
x /= 10;
}
while(!s.empty() ) {
putchar(s.top() + '0');
s.pop();
}
}
int n;
const int N = 5e5 + 5;
const int L = 20;
int Y[N], R[N];
int st[N][L + 5];
map <int, int> mp;
int m;
int main (void) {
n = read();
for(int i = 1; i <= n; i++) Y[i] = read(), R[i] = read();
for(int i = 1; i <= n; i++) st[i][0] = R[i], mp[Y[i]] = i;
for(int i = 1; i < L; i++) {
for(int j = 1; j + (1 << i) - 1 <= n; j++) {
st[j][i] = max(st[j][i - 1], st[j + (1 << (i - 1))][i - 1]);
}
}
m = read();
for(int i = 1; i <= m; i++) {
int y, x;
y = read(), x = read();
bool flag1, flag2;
flag1 = flag2 = false;
bool findy = (mp.find(y) != mp.end());
bool findx = (mp.find(x) != mp.end());
if(!findx) {
if(!findy) {
cout << "maybe\n";
continue;
} else {
int l = mp[y] + 1;
int r = lower_bound(Y + 1, Y + 1 + n, x) - Y;
int k = (int)(log2(r - l + 1));
if(max(st[l][k], st[r - (1 << k) + 1][k]) < R[mp[y]]) {
cout << "maybe\n";
continue;
} else {
cout << "false\n";
continue;
}
}
} else {
if(findy) {
if(R[mp[y]] < R[mp[x]]) {
cout << "false\n";
continue;
} else {
int l = mp[y] + 1;
int r = mp[x] - 1;
int k = (int)(log2(r - l + 1));
if(max(st[l][k], st[r - (1 << k) + 1][k]) >= R[mp[x]]) {
cout << "false\n";
continue;
} else {
if(mp[x] - mp[y] == x - y) cout << "true\n";
else cout << "maybe\n";
continue;
}
}
} else {
int l = lower_bound(Y + 1, Y + 1 + n, y) - Y;
int r = mp[x] - 1;
int k = (int)(log2(r - l + 1));
if(max(st[l][k], st[r - (1 << k) + 1][k]) >= R[mp[x]]) cout << "false\n";
else cout << "maybe\n";
continue;
}
}
}
return 0;
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...