#include "bits/extc++.h"
using namespace std;
template <typename T>
void dbgh(const T& t) {
cerr << t << endl;
}
template <typename T, typename... U>
void dbgh(const T& t, const U&... u) {
cerr << t << " | ";
dbgh(u...);
}
#ifdef DEBUG
#define dbg(...) \
cerr << "L" << __LINE__ << " [" << #__VA_ARGS__ << "]" \
<< ": "; \
dbgh(__VA_ARGS__)
#else
#define cerr \
if (false) \
cerr
#define dbg(...)
#endif
#define endl "\n"
#define long int64_t
#define sz(x) int((x).size())
void solve() {
int n, m;
cin >> n >> m;
array<int, 3> arr[m];
for (int i = 0; i < m; i++) {
cin >> arr[i][0] >> arr[i][1];
arr[i][2] = i;
}
sort(arr, arr + m);
int c1 = 1, c2 = 1;
bool ans[m];
for (auto& [l, r, i] : arr) {
dbg(c1, c2);
if (l <= c1 && l <= c2) {
if (c1 > c2) {
c2 = max(c2, r + 1);
ans[i] = true;
} else {
c1 = max(c1, r + 1);
ans[i] = false;
}
} else if (l <= c1) {
c1 = max(c1, r + 1);
ans[i] = false;
} else if (l <= c2) {
c2 = max(c2, r + 1);
ans[i] = true;
}
}
dbg(c1, c2);
if (c1 > n && c2 > n) {
cout << "yes" << endl;
// for (auto& a : ans) {
// cout << a;
// }
// cout << endl;
} else {
cout << "impossible" << endl;
}
}
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
cin.exceptions(ios::failbit);
solve();
}
Compilation message
alternating.cpp: In function 'void solve()':
alternating.cpp:42:7: warning: variable 'ans' set but not used [-Wunused-but-set-variable]
42 | bool ans[m];
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
yes is not a string of length exactly 15 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
yes is not a string of length exactly 15 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
yes is not a string of length exactly 15 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
21 ms |
1488 KB |
yes is not a string of length exactly 100000 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
yes is not a string of length exactly 15 |
2 |
Halted |
0 ms |
0 KB |
- |