This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
const int N = 1e6 + 10;
int r[N], c[N];
int h, w;
void give_initial_chart(int _h, int _w, vector<int> _r, vector<int> _c) {
for(int i = 0; i < _h * _w; i++) cout << _r[i] << " " << _c[i] << endl;
h = _h; w = _w;
for(int i = 0; i < h * w; i++) r[i] = _r[i], c[i] = _c[i];
// for(int i = 0; i < h * w; i++) cout << r[i] << " " << c[i] << endl;
}
int swap_seats(int a, int b) {
swap(r[a], r[b]);
swap(c[a], c[b]);
int up = 1e9, down = 0, leftt = 1e9, rightt = 0, ans = 0;
for(int i = 0; i < h * w; i++) {
// cerr << i << endl;
up = min(up, r[i]);
down = max(down, r[i]);
leftt = min(leftt, c[i]);
rightt = max(rightt, c[i]);
// cout << r[i] << " " << c[i] << endl;
// cout << up << " " << down << " " << leftt << " " << rightt << " " << i << endl;
if ((down - up + 1) * (rightt - leftt + 1) == i + 1) {
ans++;
}
}
return ans;
}
#ifdef ngu
int main() {
freopen ("task.inp", "r", stdin);
freopen ("task.out", "w", stdout);
int _h, _w; cin >> _h >> _w;
vector<int> _r(_h * _w), _c(_h * _w);
for(int i = 0; i < _h; i++) for(int j = 0; j < _w; j++) {
int x; cin >> x;
_r[x] = i;
_c[x] = j;
}
give_initial_chart(_h, _w, _r, _c);
int q; cin >> q;
while (q--) {
int a, b; cin >> a >> b;
cout << swap_seats(a, b) << endl;
}
}
#endif // ngu
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |