# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
644917 | BackNoob | Topovi (COCI15_topovi) | C++14 | 1430 ms | 35164 KiB |
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 ll long long
#define fi first
#define se second
#define endl '\n'
#define MASK(i) (1LL << (i))
#define ull unsigned long long
#define ld long double
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define BIT(x , i) ((x >> (i)) & 1)
#define TASK "task"
#define sz(s) (int) (s).size()
using namespace std;
const int mxN = 5e5 + 227;
const int inf = 1e9 + 277;
const int mod = 1e9 + 7;
const ll infll = 1e18 + 7;
const int base = 307;
const int LOG = 20;
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
struct item{
int r1, c1, r2, c2;
} query[mxN];
int n;
int k;
int p;
map<int, int> row;
map<int, int> col;
map<int, int> cntrow;
map<int, int> cntcol;
map<pair<int, int>, int> val;
int timer = 0;
ll res = 0;
void del(int r, int c)
{
if(row[r] == 0) res -= (n - sz(col));
res -= cntcol[row[r]];
if(col[c] == 0) res -= (n - sz(row));
res -= cntrow[col[c]];
if(row[r] == col[c]) ++res;
cntrow[row[r]]--;
cntcol[col[c]]--;
row[r] ^= val[{r, c}];
col[c] ^= val[{r, c}];
cntrow[row[r]]++;
cntcol[col[c]]++;
val[{r, c}] = 0;
if(row[r] == 0) res += (n - sz(col));
res += cntcol[row[r]];
if(col[c] == 0) res += (n - sz(row));
res += cntrow[col[c]];
if(row[r] == col[c]) --res;
}
void add(int r, int c)
{
if(row[r] == 0) res -= (n - sz(col));
res -= cntcol[row[r]];
if(col[c] == 0) res -= (n - sz(row));
res -= cntrow[col[c]];
if(row[r] == col[c]) ++res;
cntrow[row[r]]--;
cntcol[col[c]]--;
row[r] ^= val[{r, c}];
col[c] ^= val[{r, c}];
cntrow[row[r]]++;
cntcol[col[c]]++;
if(row[r] == 0) res += (n - sz(col));
res += cntcol[row[r]];
if(col[c] == 0) res += (n - sz(row));
res += cntrow[col[c]];
if(row[r] == col[c]) --res;
}
void solve()
{
cin >> n >> k >> p;
for(int i = 1; i <= k; i++) {
int r, c, x;
cin >> r >> c >> x;
row[r] ^= x;
col[c] ^= x;
val[{r, c}] = x;
}
for(int i = 1; i <= p; i++) {
cin >> query[i].r1 >> query[i].c1 >> query[i].r2 >> query[i].c2;
row[query[i].r1] ^= 0;
row[query[i].r2] ^= 0;
col[query[i].c1] ^= 0;
col[query[i].c2] ^= 0;
}
res = 1LL * (n - sz(row)) * (n - sz(col));
for(auto it : col) cntcol[it.se]++;
for(auto it : row) cntrow[it.se]++;
for(auto it : row) {
if(it.se == 0) res += (n - sz(col));
res += cntcol[it.se];
}
for(auto it : col) {
if(it.se == 0) res += (n - sz(row));
}
for(int i = 1; i <= p; i++) {
int r1, c1, r2, c2;
r1 = query[i].r1;
c1 = query[i].c1;
r2 = query[i].r2;
c2 = query[i].c2;
val[{r2, c2}] = val[{r1, c1}];
del(r1, c1);
add(r2, c2);
cout << 1LL * n * n - res << endl;
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int tc = 1;
//cin >> tc;
while(tc--) {
solve();
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |