#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)
#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif
#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
advance(it, -n);
return it;
}
template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
advance(it, n);
return it;
}
#endif
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;
const double EPS = 1e-9;
const double PI = 3.141592653589793238462;
template<typename T>
inline T sq(T a) { return a * a; }
//#ifdef LOCAL_MACHINE
//#endif
ll ops = 0, cost = 0;
int comp(int i, int j) {
if (i == j) return 0;
ops++;
assert(ops <= ( ll )1e5);
printf("cmp %d %d\n", i, j);
fflush(stdout);
int res;
scanf("%d", &res);
return res;
}
void rev(int i, int j) {
if (i == j) return;
cost += j - i + 1;
ops++;
assert(cost <= ( ll )3e6);
assert(ops <= ( ll )1e5);
printf("reverse %d %d\n", i, j);
fflush(stdout);
}
int main() {
//freopen("", "r", stdin);
//freopen("", "w", stdout);
int len_a, len_b;
scanf("%d %d", &len_a, &len_b);
int a = 1, b = len_a + 1, add = 0;
while (a <= len_a + add && b <= len_a + len_b) {
int lo = a, hi = len_a + add;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (comp(mid, b) <= 0) {
a = mid + 1;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
//while (a <= len_a + add && comp(a, b) <= 0) a++;
if (a > len_a + add) break;
int st = b;
lo = b, hi = len_a + len_b;
while (lo <= hi) {
int mid = (lo + hi) >> 1;
if (comp(a, mid) > 0) {
b = mid;
lo = mid + 1;
} else {
hi = mid - 1;
}
}
//while (b + 1 <= len_a + len_b && comp(a, b + 1) > 0) b++;
add += b - st + 1;
rev(a, b);
rev(a, a + (b - st));
rev(a + (b - st) + 1, b);
b++;
a += add;
}
puts("end");
fflush(stdout);
return 0;
}
Compilation message
nizovi.cpp: In function 'int comp(int, int)':
nizovi.cpp:61:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &res);
^
nizovi.cpp: In function 'int main()':
nizovi.cpp:79:35: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &len_a, &len_b);
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
2 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
3 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
4 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
5 |
Incorrect |
3 ms |
2020 KB |
Incorrect |
6 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
7 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
8 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
9 |
Incorrect |
0 ms |
2020 KB |
Incorrect |
10 |
Incorrect |
0 ms |
2020 KB |
Incorrect |