提出 #75672665
ソースコード 拡げる
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { return a < b ? a = b, 1 : 0; }
template<class T> inline bool chmin(T& a, T b) { return a > b ? a = b, 1 : 0; }
const int MOD = 1e9 + 7;
vector<int> bit;
void add(int idx, int val, int last) {
for (; idx <= last; idx += idx & -idx) {
bit[idx] += val;
}
}
int query(int idx) {
int sum = 0;
for (; idx > 0; idx -= idx & -idx)
sum += bit[idx];
return sum;
}
void solve() {
int n, m;
cin>>n>>m;
vector<array<int, 3>> a(m);
for (int i = 0; i < m; i++) {
cin >> a[i][0] >> a[i][1];
a[i][2] = i;
}
int q;cin>>q;
vector<array<int, 3>> queries(q);
for (int i = 0; i < q; i++) {
cin >> queries[i][0] >> queries[i][1];
queries[i][2] = i;
}
bit.assign(n + 2, 0);
vector<array<int, 3>> byL = a;
vector<array<int, 3>> byR = a;
vector<array<int, 3>> byLd = a;
sort(byL.begin(), byL.end(), [](const array<int, 3>& x, const array<int, 3>& y) {
if (x[0] != y[0]) return x[0] < y[0];
return x[1] > y[1];
});
sort(byR.begin(), byR.end(), [](const array<int, 3>& x, const array<int, 3>& y) {
if (x[1] != y[1]) return x[1] < y[1];
return x[0] < y[0];
});
sort(byLd.begin(), byLd.end(), [](const array<int, 3>& x, const array<int, 3>& y) {
return x[0] > y[0];
});
sort(queries.begin(), queries.end(), [](const array<int, 3>& x, const array<int, 3>& y) {
return x[0] > y[0];
});
vector<string> ans(q);
int ptr = 0;
for (int i = 0; i < q; i++) {
int S = queries[i][0];
int T = queries[i][1];
int curr = queries[i][2];
while (ptr < m && byLd[ptr][0] >= S) {
add(byLd[ptr][1], 1, n);
ptr++;
}
bool flag = false;
vector<array<int, 3>> c1;
array<int, 3> temp1 = {S, -1, -1};
auto it1 = lower_bound(byL.begin(), byL.end(), temp1, [](const array<int, 3>& x, const array<int, 3>& y) {
return x[0] < y[0];
});
for (int j = 0; j < 2 && it1 != byL.end() && (*it1)[0] == S; ++j, ++it1) {
c1.pb(*it1);
}
vector<array<int, 3>> c2;
array<int, 3> temp2 = {-1, T, -1};
auto it2 = lower_bound(byR.begin(), byR.end(), temp2, [](const array<int, 3>& x, const array<int, 3>& y) {
return x[1] < y[1];});
for (int j = 0; j < 2 && it2 != byR.end() && (*it2)[1] == T; ++j, ++it2) {
c2.pb(*it2);}
for (auto u : c1) {
for (auto v : c2) {
if (u[2] != v[2] && v[0] <= u[1] + 1) {
flag = true;
}
}}
if (!flag) {
bool exact = false;
for (auto u : c1) {
if (u[1] == T) exact = true;
}
if (exact) {
int cnt = query(T);
if (cnt >= 2) {
flag= true;
}
}
}
ans[curr]= flag?"Yes" : "No";
}
for (int i = 0; i < q; ++i) {
cout << ans[i] << "\n";
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tt = 1;
while (tt--) {
solve();
}
return 0;
}
提出情報
ジャッジ結果
| セット名 |
Sample |
All |
| 得点 / 配点 |
0 / 0 |
0 / 475 |
| 結果 |
|
|
| セット名 |
テストケース |
| Sample |
00_sample_00.txt, 00_sample_01.txt |
| All |
00_sample_00.txt, 00_sample_01.txt, 01_handmade_00.txt, 01_handmade_01.txt, 01_handmade_02.txt, 01_handmade_03.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 02_random_15.txt, 02_random_16.txt, 02_random_17.txt, 02_random_18.txt, 02_random_19.txt, 02_random_20.txt |
| ケース名 |
結果 |
実行時間 |
メモリ |
| 00_sample_00.txt |
WA |
3 ms |
6252 KiB |
| 00_sample_01.txt |
WA |
2 ms |
6240 KiB |
| 01_handmade_00.txt |
WA |
22 ms |
12636 KiB |
| 01_handmade_01.txt |
WA |
18 ms |
11476 KiB |
| 01_handmade_02.txt |
WA |
29 ms |
14220 KiB |
| 01_handmade_03.txt |
AC |
38 ms |
15456 KiB |
| 02_random_00.txt |
WA |
149 ms |
24872 KiB |
| 02_random_01.txt |
WA |
146 ms |
24928 KiB |
| 02_random_02.txt |
AC |
82 ms |
24136 KiB |
| 02_random_03.txt |
AC |
104 ms |
24132 KiB |
| 02_random_04.txt |
WA |
146 ms |
24824 KiB |
| 02_random_05.txt |
WA |
146 ms |
24928 KiB |
| 02_random_06.txt |
WA |
147 ms |
24904 KiB |
| 02_random_07.txt |
WA |
144 ms |
24356 KiB |
| 02_random_08.txt |
WA |
145 ms |
24800 KiB |
| 02_random_09.txt |
WA |
142 ms |
24012 KiB |
| 02_random_10.txt |
AC |
114 ms |
24848 KiB |
| 02_random_11.txt |
WA |
133 ms |
24896 KiB |
| 02_random_12.txt |
WA |
146 ms |
24824 KiB |
| 02_random_13.txt |
AC |
113 ms |
25032 KiB |
| 02_random_14.txt |
WA |
132 ms |
24900 KiB |
| 02_random_15.txt |
WA |
146 ms |
24900 KiB |
| 02_random_16.txt |
AC |
115 ms |
24864 KiB |
| 02_random_17.txt |
WA |
134 ms |
24772 KiB |
| 02_random_18.txt |
WA |
146 ms |
24972 KiB |
| 02_random_19.txt |
WA |
6 ms |
7076 KiB |
| 02_random_20.txt |
WA |
11 ms |
8388 KiB |