#include <bits/stdc++.h> #include <unistd.h> using namespace std; #define SZ(x) ((int) (x).size()) #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; #define DBG(X) typedef long long LL; typedef unsigned long long ULL; #define BIGMOD 1000012177LL struct Pos { int row, col; Pos(int row, int col) : row(row), col(col) {}; bool empty() { return row < 0 || col < 0; } }; struct Query { Pos p; int index; int initialValueAtPos; Query(Pos p, int index, int initialValueAtPos) : p(p), index(index), initialValueAtPos(-1) {} }; struct Rect { Pos topLeft, bottomRight; Rect(Pos topLeft, Pos bottomRight) : topLeft(topLeft), bottomRight(bottomRight) {} }; struct RemappedValue { LL val; int originalIdx; RemappedValue(LL val, int _originalIdx) : val(val), originalIdx(_originalIdx) {} bool operator<(const RemappedValue &b) { return val < b.val; } }; struct Zajetosc { LL val; int prevIdx,nextIdx; Zajetosc() { val = 0; prevIdx = -1; nextIdx = -1;} Zajetosc(LL val, int prevIdx, int nextIdx) : val(val), prevIdx(prevIdx), nextIdx(nextIdx) {}; }; template<typename T> class SegmentTree { public: vector<T> tree; vector<T> lazy; int size; SegmentTree(int n) { size = n; int s = (1 << ((int)ceil(log2(n))+1)); tree = vector<T>(s, 0); lazy = vector<T>(s, 0); } void updateLazyChildren(int index, T value) { if (2*index + 1 < SZ(lazy)) lazy[2*index+1] = (lazy[2*index + 1] + 1)%2; if (2*index + 2 < SZ(lazy)) lazy[2*index + 2] = (lazy[2*index + 2] + 1)%2; } void updateRange(int l, int r, T value) { updateRange(0,size-1, 0, l, r, value); } void updateRange(int start, int end, int index, int l, int r, T value) { if (lazy[index] != 0) { updateLazyChildren(index, lazy[index]); tree[index] = (end - start + 1) - tree[index]; lazy[index] = 0; } if (start > end || start > r || end < l) return; if( start >= l && end <= r) { tree[index] = (end - start + 1) - tree[index]; updateLazyChildren(index, value); return; } int mid = start + (end - start)/2; updateRange(start, mid, 2*index + 1,l, r, value); updateRange(mid + 1, end, 2*index + 2,l, r, value); tree[index] = tree[2*index + 1] + tree[2*index + 2]; } T getQuery(int l, int r) { return getQuery(0, size-1, 0, l, r); } T getQuery(int start, int end, int index, int l, int r) { if (start > end || start > r || end < l) return (0); if (lazy[index] != 0) { updateLazyChildren(index, lazy[index]); tree[index] = (end - start + 1) - tree[index]; lazy[index] = 0; } if (start >= l && end <= r) return tree[index]; int mid = start + (end - start)/2; T p1 = getQuery(start, mid, 2*index + 1, l, r); T p2 = getQuery(mid + 1, end, 2*index + 2, l,r); return (p1 + p2); } }; // both intervals and queryMap have lenght 'n' vector<RemappedValue> calculateSums(int n, const vector<vector<pair<pair<int, int>, int> > > &intervals, vector<Query> &originalQueries, bool shouldCalculateQueries) { vector<RemappedValue> res; SegmentTree<int> tree(n); vector<vector<int> > queriesPtrs; vector<char> alreadySeen; alreadySeen.resize(n); for (int i=0; i < int(alreadySeen.size()); i++) alreadySeen[i] = -1; if (shouldCalculateQueries) // only use that when calculating ROWS!! { queriesPtrs.resize(n); for (Query &q : originalQueries) { queriesPtrs[q.p.row].emplace_back(q.index); } } for (int i=0; i < n; i++) { // i-th ROW for (auto &p : intervals[i]) if (p.second == 1) tree.updateRange(p.first.first, p.first.second, 1); if (shouldCalculateQueries) { vector<int> &qs = queriesPtrs[i]; for (int qIdx : qs) { Query &q = originalQueries[qIdx]; //printf("qIdx=%d\n", qIdx); if (alreadySeen[q.p.col] == -1) { //printf("alreadySeen[col=%d]==-1\n", q.p.col); q.initialValueAtPos = tree.getQuery(q.p.col, q.p.col); alreadySeen[q.p.col] = q.initialValueAtPos; //printf("... alreadySeen[col=%d] set to %d\n", q.p.col, alreadySeen[q.p.col]); } else { //printf("improving query on col %d\n", q.p.col); q.initialValueAtPos = 1 - alreadySeen[q.p.col]; alreadySeen[q.p.col] = q.initialValueAtPos; } if (q.p.row != i) printf("error: query should be processed in correct row\n"); } // clear alreadySeen values for (int qIdx : qs) alreadySeen[originalQueries[qIdx].p.col] = -1; } LL val = tree.getQuery(0, n-1); res.push_back(RemappedValue(val, i)); for (auto &p : intervals[i]) if (p.second == 2) tree.updateRange(p.first.first, p.first.second, 1); } return res; } void selftest() { SegmentTree<int> tree(100); tree.updateRange(0, 9, 1); tree.updateRange(20,30, 1); tree.updateRange(1,2, 1); printf("query=%d\n", tree.getQuery(0, 9)); map<int, int> samePointQueries; samePointQueries[15] = 3; printf("selftest query: %d\n", samePointQueries[15]); } void print_vec(vector<RemappedValue> &v) { for (auto x : v) { printf("%lld ", x.val); } printf("\n"); } LL ileMozliwychRuchow(LL n, LL Xcnt, vector<RemappedValue> &rowSums, vector<RemappedValue> &colSums) { DBG(printf("ileMozliwychRuchow(n=%lld, Xcnt=%lld):\n", n, Xcnt)); LL sumaPoWierszach = 0; LL sumaPoKolumnach = 0; int j = -1; int i = -1; LL maxBlocked = 0; while (i < n && j < n) { LL nextRowVal = (i+1 < n) ? rowSums[i+1].val : -1; LL nextColVal = (j+1 < n) ? colSums[j+1].val : -1; if (nextRowVal == -1 && nextColVal == -1) break; if (nextRowVal == -1) { sumaPoKolumnach += nextColVal; j++; continue; } else if (nextColVal == -1) { sumaPoWierszach += nextRowVal; i++; continue; } else if (nextRowVal < nextColVal) { sumaPoWierszach += nextRowVal; i++; } else { sumaPoKolumnach += nextColVal; j++; } LL currentAll = (i+1) * (j+1); LL currentBlocked = currentAll - sumaPoKolumnach - sumaPoWierszach; maxBlocked = max(maxBlocked, currentBlocked); DBG(printf("Processing row=%d col=%d nextRowVal=%lld nextColVal=%lld currentBlocked=%lld\n", i, j, nextRowVal, nextColVal, currentBlocked)); } return min(Xcnt, n*n - Xcnt - maxBlocked); } LL howManyBlockedIf(LL ileWierszySoFar, LL ileColumnSoFar, LL sumaPoWierszach, LL sumaPoKolumnach) { LL res = ileWierszySoFar * ileColumnSoFar - sumaPoKolumnach - sumaPoWierszach; //printf("how many blocked if: %lld, ileWierszySoFar=%lld ileColumnSoFar=%lld sumaPoWierszach=%lld sumaPoKolumnach=%lld\n", res, ileWierszySoFar, ileColumnSoFar, sumaPoWierszach,sumaPoKolumnach ); return res; } LL ileMozliwychRuchowFaster(LL n, LL Xcnt, vector<Zajetosc> &ileWierszyOZajetosci, vector<Zajetosc> &ileKolumnOZajetosci, int firstNonEmptyRowSum, int firstNonEmptyColSum, bool heureza) { /*for (int i=0; i < n; i++) { Zajetosc &z = ileWierszyOZajetosci[i]; if (z.val == 0) continue; printf("Wierszy o zajetosci %d jest %lld (prev=%d, next=%d)\n", i, z.val, z.prevIdx, z.nextIdx); } for (int i=0; i < n; i++) { Zajetosc &z = ileKolumnOZajetosci[i]; if (z.val == 0) continue; printf("Kolumn o zajetosci %d jest %lld (prev=%d, next=%d)\n", i, z.val, z.prevIdx, z.nextIdx); }*/ LL sumaPoWierszach = 0; LL sumaPoKolumnach = 0; int ileWierszySoFar = 0; int ileColumnSoFar = 0; int i = firstNonEmptyRowSum; int j = firstNonEmptyColSum; LL maxBlocked = 0; ileWierszySoFar += ileWierszyOZajetosci[i].val; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * i; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; DBG(printf("Starting at row=%d col=%d\n", i, j)); static LL heurezaCounter = 300000 * 1000LL; LL loopCounter = 0; while (1) { if (ileWierszyOZajetosci[i].nextIdx == -1 || ileKolumnOZajetosci[j].nextIdx == -1) { //printf("breaking the loop\n"); break; } --heurezaCounter; loopCounter++; if (heurezaCounter < 0 && loopCounter > 1000) break; // Maxymalizuj currentBlocked czyli ileWierszySoFar * ileColumnSoFar - sumaPoKolumnach - sumaPoWierszach LL currentAll = ileWierszySoFar * ileColumnSoFar; LL currentBlocked = currentAll - sumaPoKolumnach - sumaPoWierszach; maxBlocked = max(maxBlocked, currentBlocked); DBG(printf("Processing row=%d col=%d currentBlocked=%lld wierszySoFar %d, columSoFar=%d sumaPoWierszach: %lld sumaPoKolumnach: %lld\n", i, j, currentBlocked, ileWierszySoFar, ileColumnSoFar, sumaPoWierszach, sumaPoKolumnach)); //if (currentBlocked < 0) break; //DBG(printf("Wierszy o zajetosci %d jest %lld, Kolumn o zajetosci %lld jest %d\n", i, ileWierszyOZajetosci[i].val, j, ileKolumnOZajetosci[j].val)); if (ileWierszyOZajetosci[i].nextIdx == -1) { //printf("case 1\n"); j = ileKolumnOZajetosci[j].nextIdx; if (j == -1) break; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; } else if (ileKolumnOZajetosci[j].nextIdx == -1) { //printf("case 2\n"); i = ileWierszyOZajetosci[i].nextIdx; if (i == -1) break; ileWierszySoFar += ileWierszyOZajetosci[i].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * j; } else if (howManyBlockedIf(ileWierszySoFar + ileWierszyOZajetosci[ileWierszyOZajetosci[i].nextIdx].val, ileColumnSoFar, sumaPoWierszach + ileWierszyOZajetosci[ileWierszyOZajetosci[i].nextIdx].val * ileWierszyOZajetosci[i].nextIdx, sumaPoKolumnach) > howManyBlockedIf(ileWierszySoFar, ileColumnSoFar + ileKolumnOZajetosci[ileKolumnOZajetosci[j].nextIdx].val, sumaPoWierszach, sumaPoKolumnach + ileKolumnOZajetosci[ileKolumnOZajetosci[j].nextIdx].val * ileKolumnOZajetosci[j].nextIdx) ) { //printf("case 3\n"); i = ileWierszyOZajetosci[i].nextIdx; if (i == -1) break; ileWierszySoFar += ileWierszyOZajetosci[i].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * i; } else { //printf("case 4\n"); j = ileKolumnOZajetosci[j].nextIdx; if (j == -1) break; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; } } DBG(printf("result=%lld Xes: %lld wolnych:%lld\n", min(Xcnt, n*n - Xcnt - maxBlocked), Xcnt, n*n - Xcnt)); return min(Xcnt, n*n - Xcnt - maxBlocked); } void debugValidateRange(int n, int v) { if (v < 0 || v > n) printf("error: cols or row sum value is out of range!\n"); } vector<Zajetosc> calculateZajetosc(int n, vector<RemappedValue> &v) { vector<Zajetosc> res; res.resize(n+1); for (int i=0; i < n; i++) { res[v[i].val].val++; } int prevNonEmpty = -1; int nextNonEmpty = -1; for (int i=0; i < n+1; i++) { if (res[i].val) { res[i].prevIdx = prevNonEmpty; prevNonEmpty = i; } } for (int i=n; i >= 0; i--) { if (res[i].val) { res[i].nextIdx = nextNonEmpty; nextNonEmpty = i; } } return res; } void updateZajetoscPtr(vector<Zajetosc> &v, int k, int aCase, int providedPrev) { //printf("updateZajetoscPtr v[%d]=%lld aCase=%d providedPrev=%d\n", k, v[k].val, aCase, providedPrev); if (aCase == 1 && v[k].val == 0) { int prev = v[k].prevIdx; int next = v[k].nextIdx; if (prev!=-1) { v[prev].nextIdx = next; } if (next != -1) { v[next].prevIdx = prev; } return; } if (aCase == 2) { if (v[k].val == 1) { // to jest nowa wartosc, wiec trzeba policzyc jej prev i Next if (providedPrev > 0) { int next = k + providedPrev; int prev = v[next].prevIdx; if (prev != -1) v[prev].nextIdx = k; v[k].nextIdx = next; v[k].prevIdx = prev; v[next].prevIdx = k; } if (providedPrev < 0) { int prev = k + providedPrev; int next = v[prev].nextIdx; v[prev].nextIdx = k; v[k].nextIdx = next; v[k].prevIdx = prev; if (next != -1) v[next].prevIdx = k; } return; } int prev = v[k].prevIdx; int next = v[k].nextIdx; if (prev != -1 && v[prev].val == 0) v[k].prevIdx = v[prev].prevIdx; if (next != -1 && v[next].val == 0) v[k].nextIdx = v[next].nextIdx; } } vector<LL> calculateAnswerToQueries(vector<RemappedValue> &rowSums, vector<RemappedValue> &colSums, vector<Query> &queries) { vector<LL> res; LL n = rowSums.size(); LL Xcnt = 0; LL Xcnt_assert = 0; // always calulate first answer for (int i=0; i < n; i++) { LL rs = rowSums[i].val; LL cs = colSums[i].val; Xcnt += rs; Xcnt_assert += cs; } if (Xcnt != Xcnt_assert) printf("error: sum in rows and columns should be the same!!\n"); //DBG(printf("Xcnt=%lld\n", Xcnt)); sort(colSums.begin(), colSums.end()); sort(rowSums.begin(), rowSums.end()); vector<int> remapColSums, remapRowSums; remapColSums.resize(n); remapRowSums.resize(n); REP(i,n) remapRowSums[rowSums[i].originalIdx] = i; REP(j,n) remapColSums[colSums[j].originalIdx] = j; vector<Zajetosc> ileWierszyOZajetosci = calculateZajetosc(n, rowSums); vector<Zajetosc> ileKolumnOZajetosci = calculateZajetosc(n, colSums); int minNonEmptyRowSum = 0; int minNonEmptyColSum = 0; REP(i,n) if (ileWierszyOZajetosci[i].val) { minNonEmptyRowSum = i; break; } REP(j,n) if (ileKolumnOZajetosci[j].val) { minNonEmptyColSum = j; break; } //res.emplace_back(ileMozliwychRuchow(n, Xcnt, rowSums, colSums)); res.emplace_back(ileMozliwychRuchowFaster(n, Xcnt, ileWierszyOZajetosci, ileKolumnOZajetosci, minNonEmptyRowSum, minNonEmptyColSum, false)); for (Query &query : queries) { DBG(printf("processng query %d\n", query.index)); int rowIdx = remapRowSums[query.p.row]; int colIdx = remapColSums[query.p.col]; // we flip from 0 to 1 int ileWWierszu = rowSums[rowIdx].val; int ileWKolumnie = colSums[colIdx].val; int lastIleWWierszu = ileWWierszu; int lastIleWKolumnie = ileWKolumnie; int prev = -30; if (query.initialValueAtPos == 0) { ++rowSums[rowIdx].val; ++colSums[colIdx].val; ++Xcnt; ++ileWWierszu; ++ileWKolumnie; prev = -1; } else { // flip from 1 to 0 --rowSums[rowIdx].val; --colSums[colIdx].val; --Xcnt; --ileWWierszu; --ileWKolumnie; prev = 1; } ++ileWierszyOZajetosci[ileWWierszu].val; ++ileKolumnOZajetosci[ileWKolumnie].val; updateZajetoscPtr(ileWierszyOZajetosci, ileWWierszu, 2, prev); updateZajetoscPtr(ileKolumnOZajetosci, ileWKolumnie, 2, prev); --ileWierszyOZajetosci[lastIleWWierszu].val; --ileKolumnOZajetosci[lastIleWKolumnie].val; updateZajetoscPtr(ileWierszyOZajetosci, lastIleWWierszu, 1, 30); updateZajetoscPtr(ileKolumnOZajetosci, lastIleWKolumnie, 1, 30); if (minNonEmptyRowSum - 1 >= 0 && ileWierszyOZajetosci[minNonEmptyRowSum - 1].val > 0) { minNonEmptyRowSum--; } if (minNonEmptyColSum - 1 >= 0 && ileKolumnOZajetosci[minNonEmptyColSum - 1].val > 0) { minNonEmptyColSum--; } if (ileWierszyOZajetosci[minNonEmptyRowSum].val == 0) minNonEmptyRowSum++; if (ileKolumnOZajetosci[minNonEmptyColSum].val == 0) minNonEmptyColSum++; debugValidateRange(n, rowSums[rowIdx].val); debugValidateRange(n, colSums[colIdx].val); // DEBUG: /*sort(colSums.begin(), colSums.end()); sort(rowSums.begin(), rowSums.end()); REP(i,n) remapRowSums[rowSums[i].originalIdx] = i; REP(j,n) remapColSums[colSums[j].originalIdx] = j; DBG(printf("Row sums: ")); DBG(print_vec(rowSums)); DBG(printf("Col sums: ")); DBG(print_vec(colSums));*/ // END OF DEBUG //res.emplace_back(ileMozliwychRuchow(n, Xcnt, rowSums, colSums)); res.emplace_back(ileMozliwychRuchowFaster(n, Xcnt, ileWierszyOZajetosci, ileKolumnOZajetosci, minNonEmptyRowSum, minNonEmptyColSum, true)); } return res; } vector<LL> solve(int n, vector<Rect> &updates, vector<Query> &kingsRequests) { //selftest(); vector<LL> res; vector<vector<pair<pair<int, int>, int> > > intervals; intervals.resize(n); for (auto &u : updates) { pair<int, int> rg = make_pair(u.topLeft.col, u.bottomRight.col); intervals[u.topLeft.row].emplace_back(make_pair(rg, 1)); // open intervals[u.bottomRight.row].emplace_back(make_pair(rg, 2)); // close } vector<RemappedValue> rowSums = calculateSums(n, intervals, kingsRequests, true); /*REP(i, kingsRequests.size()) { Query &q = kingsRequests[i]; DBG(printf("Q{idx:%d,pos=(%d,%d),bit:%d}\n", q.index, q.p.row, q.p.col, q.initialValueAtPos)); }*/ intervals.clear(); intervals.resize(n); for (auto &u : updates) { pair<int, int> rg = make_pair(u.topLeft.row, u.bottomRight.row); intervals[u.topLeft.col].emplace_back(make_pair(rg, 1)); // open intervals[u.bottomRight.col].emplace_back(make_pair(rg, 2)); // close } vector<RemappedValue> colSums = calculateSums(n, intervals, kingsRequests, false); return calculateAnswerToQueries(rowSums, colSums, kingsRequests); } int main() { int n,m,q; int rc = scanf("%d%d%d", &n, &m, &q); if (rc < 0) { return 0; } vector<Rect> updates; for (int i=0; i < m; i++) { int x1, y1, x2, y2; rc = scanf("%d%d%d%d", &x1, &y1, &x2, &y2); if (rc < 0) { return 0; } updates.emplace_back(Rect(Pos(x1-1, y1-1), Pos(x2-1, y2-1))); } vector<Query> kingsRequests; for (int i=0; i < q; i++) { int x,y; rc = scanf("%d%d", &x, &y); if (rc < 0) { return 0; } kingsRequests.emplace_back(Query(Pos(x-1, y-1),i, -1)); } vector<LL> res = solve(n, updates, kingsRequests); for (int i=0; i < int(res.size()); i++) { printf("%lld\n", res[i]); } return 0; } /* Brute: D:\devel\projects\pa2020\bal>a.exe < forum/small956.in Update 4 0 15 14 Update 8 8 10 9 Update 14 14 17 14 Update 8 4 10 4 Update 3 2 3 4 Update 14 3 14 6 Update 7 2 7 7 Update 3 15 6 17 Update 7 14 9 17 Update 4 14 8 17 Na poczatku: oooooooooooooooooo oooooooooooooooooo oooooooooooooooooo ooxxxooooooooooxxx xxxxxxxxxxxxxxoooo xxxxxxxxxxxxxxoooo xxxxxxxxxxxxxxoooo xxooooooxxxxxxxooo↔ xxxxoxxxooxxxxxooo xxxxoxxxooxxxxoxxx xxxxoxxxooxxxxxooo xxxxxxxxxxxxxxxooo xxxxxxxxxxxxxxxooo xxxxxxxxxxxxxxxooo xxxooooxxxxxxxoooo xxxxxxxxxxxxxxoooo ooooooooooooooxooo ooooooooooooooxooo Row sums: 0 0 0 6 14 14 14 9 12 14 12 15 15 15 10 14 1 1 Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 12 12 8 2 2 2 Xcnt=166 blocked=0 D:\devel\projects\pa2020\bal>a.exe < forum/small956.in Row sums: 0 0 0 6 14 14 14 9 12 14 12 15 15 15 10 14 1 1 Queries: Q{idx:0,pos=(10,12),bit:1} Q{idx:1,pos=(0,14),bit:0} Q{idx:2,pos=(10,15),bit:0} Q{idx:3,pos=(17,12),bit:0} Q{idx:4,pos=(0,16),bit:0} Q{idx:5,pos=(7,17),bit:0} Q{idx:6,pos=(12,2),bit:1} Q{idx:7,pos=(13,13),bit:1} Q{idx:8,pos=(9,9),bit:0} Q{idx:9,pos=(13,5),bit:1} Q{idx:10,pos=(9,14),bit:0} Q{idx:11,pos=(17,14),bit:1} Q{idx:12,pos=(3,5),bit:0} Q{idx:13,pos=(7,4),bit:0} Q{idx:14,pos=(8,2),bit:1} Q{idx:15,pos=(2,9),bit:0} Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 12 12 8 2 2 2 Xcnt=166 blockedXes=0 blockedEmptys=0 wolnych=158 Xcnt=166 processng query 0 Row sums: 0 0 0 6 14 14 14 9 12 14 11 15 15 15 10 14 1 1 Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 11 12 8 2 2 2 i * j - suma(0,i) + suma(0,j) */
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 | #include <bits/stdc++.h> #include <unistd.h> using namespace std; #define SZ(x) ((int) (x).size()) #define REP(i,n) for(int _n=(n), i=0;i<_n;++i) #define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i) #define FORD(i,a,b) for(int i=(a),_b=(b);i>=_b;--i) #define TRACE(x) cerr << "TRACE(" #x ")" << endl; #define DEBUG(x) cerr << #x << " = " << (x) << endl; #define DBG(X) typedef long long LL; typedef unsigned long long ULL; #define BIGMOD 1000012177LL struct Pos { int row, col; Pos(int row, int col) : row(row), col(col) {}; bool empty() { return row < 0 || col < 0; } }; struct Query { Pos p; int index; int initialValueAtPos; Query(Pos p, int index, int initialValueAtPos) : p(p), index(index), initialValueAtPos(-1) {} }; struct Rect { Pos topLeft, bottomRight; Rect(Pos topLeft, Pos bottomRight) : topLeft(topLeft), bottomRight(bottomRight) {} }; struct RemappedValue { LL val; int originalIdx; RemappedValue(LL val, int _originalIdx) : val(val), originalIdx(_originalIdx) {} bool operator<(const RemappedValue &b) { return val < b.val; } }; struct Zajetosc { LL val; int prevIdx,nextIdx; Zajetosc() { val = 0; prevIdx = -1; nextIdx = -1;} Zajetosc(LL val, int prevIdx, int nextIdx) : val(val), prevIdx(prevIdx), nextIdx(nextIdx) {}; }; template<typename T> class SegmentTree { public: vector<T> tree; vector<T> lazy; int size; SegmentTree(int n) { size = n; int s = (1 << ((int)ceil(log2(n))+1)); tree = vector<T>(s, 0); lazy = vector<T>(s, 0); } void updateLazyChildren(int index, T value) { if (2*index + 1 < SZ(lazy)) lazy[2*index+1] = (lazy[2*index + 1] + 1)%2; if (2*index + 2 < SZ(lazy)) lazy[2*index + 2] = (lazy[2*index + 2] + 1)%2; } void updateRange(int l, int r, T value) { updateRange(0,size-1, 0, l, r, value); } void updateRange(int start, int end, int index, int l, int r, T value) { if (lazy[index] != 0) { updateLazyChildren(index, lazy[index]); tree[index] = (end - start + 1) - tree[index]; lazy[index] = 0; } if (start > end || start > r || end < l) return; if( start >= l && end <= r) { tree[index] = (end - start + 1) - tree[index]; updateLazyChildren(index, value); return; } int mid = start + (end - start)/2; updateRange(start, mid, 2*index + 1,l, r, value); updateRange(mid + 1, end, 2*index + 2,l, r, value); tree[index] = tree[2*index + 1] + tree[2*index + 2]; } T getQuery(int l, int r) { return getQuery(0, size-1, 0, l, r); } T getQuery(int start, int end, int index, int l, int r) { if (start > end || start > r || end < l) return (0); if (lazy[index] != 0) { updateLazyChildren(index, lazy[index]); tree[index] = (end - start + 1) - tree[index]; lazy[index] = 0; } if (start >= l && end <= r) return tree[index]; int mid = start + (end - start)/2; T p1 = getQuery(start, mid, 2*index + 1, l, r); T p2 = getQuery(mid + 1, end, 2*index + 2, l,r); return (p1 + p2); } }; // both intervals and queryMap have lenght 'n' vector<RemappedValue> calculateSums(int n, const vector<vector<pair<pair<int, int>, int> > > &intervals, vector<Query> &originalQueries, bool shouldCalculateQueries) { vector<RemappedValue> res; SegmentTree<int> tree(n); vector<vector<int> > queriesPtrs; vector<char> alreadySeen; alreadySeen.resize(n); for (int i=0; i < int(alreadySeen.size()); i++) alreadySeen[i] = -1; if (shouldCalculateQueries) // only use that when calculating ROWS!! { queriesPtrs.resize(n); for (Query &q : originalQueries) { queriesPtrs[q.p.row].emplace_back(q.index); } } for (int i=0; i < n; i++) { // i-th ROW for (auto &p : intervals[i]) if (p.second == 1) tree.updateRange(p.first.first, p.first.second, 1); if (shouldCalculateQueries) { vector<int> &qs = queriesPtrs[i]; for (int qIdx : qs) { Query &q = originalQueries[qIdx]; //printf("qIdx=%d\n", qIdx); if (alreadySeen[q.p.col] == -1) { //printf("alreadySeen[col=%d]==-1\n", q.p.col); q.initialValueAtPos = tree.getQuery(q.p.col, q.p.col); alreadySeen[q.p.col] = q.initialValueAtPos; //printf("... alreadySeen[col=%d] set to %d\n", q.p.col, alreadySeen[q.p.col]); } else { //printf("improving query on col %d\n", q.p.col); q.initialValueAtPos = 1 - alreadySeen[q.p.col]; alreadySeen[q.p.col] = q.initialValueAtPos; } if (q.p.row != i) printf("error: query should be processed in correct row\n"); } // clear alreadySeen values for (int qIdx : qs) alreadySeen[originalQueries[qIdx].p.col] = -1; } LL val = tree.getQuery(0, n-1); res.push_back(RemappedValue(val, i)); for (auto &p : intervals[i]) if (p.second == 2) tree.updateRange(p.first.first, p.first.second, 1); } return res; } void selftest() { SegmentTree<int> tree(100); tree.updateRange(0, 9, 1); tree.updateRange(20,30, 1); tree.updateRange(1,2, 1); printf("query=%d\n", tree.getQuery(0, 9)); map<int, int> samePointQueries; samePointQueries[15] = 3; printf("selftest query: %d\n", samePointQueries[15]); } void print_vec(vector<RemappedValue> &v) { for (auto x : v) { printf("%lld ", x.val); } printf("\n"); } LL ileMozliwychRuchow(LL n, LL Xcnt, vector<RemappedValue> &rowSums, vector<RemappedValue> &colSums) { DBG(printf("ileMozliwychRuchow(n=%lld, Xcnt=%lld):\n", n, Xcnt)); LL sumaPoWierszach = 0; LL sumaPoKolumnach = 0; int j = -1; int i = -1; LL maxBlocked = 0; while (i < n && j < n) { LL nextRowVal = (i+1 < n) ? rowSums[i+1].val : -1; LL nextColVal = (j+1 < n) ? colSums[j+1].val : -1; if (nextRowVal == -1 && nextColVal == -1) break; if (nextRowVal == -1) { sumaPoKolumnach += nextColVal; j++; continue; } else if (nextColVal == -1) { sumaPoWierszach += nextRowVal; i++; continue; } else if (nextRowVal < nextColVal) { sumaPoWierszach += nextRowVal; i++; } else { sumaPoKolumnach += nextColVal; j++; } LL currentAll = (i+1) * (j+1); LL currentBlocked = currentAll - sumaPoKolumnach - sumaPoWierszach; maxBlocked = max(maxBlocked, currentBlocked); DBG(printf("Processing row=%d col=%d nextRowVal=%lld nextColVal=%lld currentBlocked=%lld\n", i, j, nextRowVal, nextColVal, currentBlocked)); } return min(Xcnt, n*n - Xcnt - maxBlocked); } LL howManyBlockedIf(LL ileWierszySoFar, LL ileColumnSoFar, LL sumaPoWierszach, LL sumaPoKolumnach) { LL res = ileWierszySoFar * ileColumnSoFar - sumaPoKolumnach - sumaPoWierszach; //printf("how many blocked if: %lld, ileWierszySoFar=%lld ileColumnSoFar=%lld sumaPoWierszach=%lld sumaPoKolumnach=%lld\n", res, ileWierszySoFar, ileColumnSoFar, sumaPoWierszach,sumaPoKolumnach ); return res; } LL ileMozliwychRuchowFaster(LL n, LL Xcnt, vector<Zajetosc> &ileWierszyOZajetosci, vector<Zajetosc> &ileKolumnOZajetosci, int firstNonEmptyRowSum, int firstNonEmptyColSum, bool heureza) { /*for (int i=0; i < n; i++) { Zajetosc &z = ileWierszyOZajetosci[i]; if (z.val == 0) continue; printf("Wierszy o zajetosci %d jest %lld (prev=%d, next=%d)\n", i, z.val, z.prevIdx, z.nextIdx); } for (int i=0; i < n; i++) { Zajetosc &z = ileKolumnOZajetosci[i]; if (z.val == 0) continue; printf("Kolumn o zajetosci %d jest %lld (prev=%d, next=%d)\n", i, z.val, z.prevIdx, z.nextIdx); }*/ LL sumaPoWierszach = 0; LL sumaPoKolumnach = 0; int ileWierszySoFar = 0; int ileColumnSoFar = 0; int i = firstNonEmptyRowSum; int j = firstNonEmptyColSum; LL maxBlocked = 0; ileWierszySoFar += ileWierszyOZajetosci[i].val; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * i; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; DBG(printf("Starting at row=%d col=%d\n", i, j)); static LL heurezaCounter = 300000 * 1000LL; LL loopCounter = 0; while (1) { if (ileWierszyOZajetosci[i].nextIdx == -1 || ileKolumnOZajetosci[j].nextIdx == -1) { //printf("breaking the loop\n"); break; } --heurezaCounter; loopCounter++; if (heurezaCounter < 0 && loopCounter > 1000) break; // Maxymalizuj currentBlocked czyli ileWierszySoFar * ileColumnSoFar - sumaPoKolumnach - sumaPoWierszach LL currentAll = ileWierszySoFar * ileColumnSoFar; LL currentBlocked = currentAll - sumaPoKolumnach - sumaPoWierszach; maxBlocked = max(maxBlocked, currentBlocked); DBG(printf("Processing row=%d col=%d currentBlocked=%lld wierszySoFar %d, columSoFar=%d sumaPoWierszach: %lld sumaPoKolumnach: %lld\n", i, j, currentBlocked, ileWierszySoFar, ileColumnSoFar, sumaPoWierszach, sumaPoKolumnach)); //if (currentBlocked < 0) break; //DBG(printf("Wierszy o zajetosci %d jest %lld, Kolumn o zajetosci %lld jest %d\n", i, ileWierszyOZajetosci[i].val, j, ileKolumnOZajetosci[j].val)); if (ileWierszyOZajetosci[i].nextIdx == -1) { //printf("case 1\n"); j = ileKolumnOZajetosci[j].nextIdx; if (j == -1) break; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; } else if (ileKolumnOZajetosci[j].nextIdx == -1) { //printf("case 2\n"); i = ileWierszyOZajetosci[i].nextIdx; if (i == -1) break; ileWierszySoFar += ileWierszyOZajetosci[i].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * j; } else if (howManyBlockedIf(ileWierszySoFar + ileWierszyOZajetosci[ileWierszyOZajetosci[i].nextIdx].val, ileColumnSoFar, sumaPoWierszach + ileWierszyOZajetosci[ileWierszyOZajetosci[i].nextIdx].val * ileWierszyOZajetosci[i].nextIdx, sumaPoKolumnach) > howManyBlockedIf(ileWierszySoFar, ileColumnSoFar + ileKolumnOZajetosci[ileKolumnOZajetosci[j].nextIdx].val, sumaPoWierszach, sumaPoKolumnach + ileKolumnOZajetosci[ileKolumnOZajetosci[j].nextIdx].val * ileKolumnOZajetosci[j].nextIdx) ) { //printf("case 3\n"); i = ileWierszyOZajetosci[i].nextIdx; if (i == -1) break; ileWierszySoFar += ileWierszyOZajetosci[i].val; sumaPoWierszach += ileWierszyOZajetosci[i].val * i; } else { //printf("case 4\n"); j = ileKolumnOZajetosci[j].nextIdx; if (j == -1) break; ileColumnSoFar += ileKolumnOZajetosci[j].val; sumaPoKolumnach += ileKolumnOZajetosci[j].val * j; } } DBG(printf("result=%lld Xes: %lld wolnych:%lld\n", min(Xcnt, n*n - Xcnt - maxBlocked), Xcnt, n*n - Xcnt)); return min(Xcnt, n*n - Xcnt - maxBlocked); } void debugValidateRange(int n, int v) { if (v < 0 || v > n) printf("error: cols or row sum value is out of range!\n"); } vector<Zajetosc> calculateZajetosc(int n, vector<RemappedValue> &v) { vector<Zajetosc> res; res.resize(n+1); for (int i=0; i < n; i++) { res[v[i].val].val++; } int prevNonEmpty = -1; int nextNonEmpty = -1; for (int i=0; i < n+1; i++) { if (res[i].val) { res[i].prevIdx = prevNonEmpty; prevNonEmpty = i; } } for (int i=n; i >= 0; i--) { if (res[i].val) { res[i].nextIdx = nextNonEmpty; nextNonEmpty = i; } } return res; } void updateZajetoscPtr(vector<Zajetosc> &v, int k, int aCase, int providedPrev) { //printf("updateZajetoscPtr v[%d]=%lld aCase=%d providedPrev=%d\n", k, v[k].val, aCase, providedPrev); if (aCase == 1 && v[k].val == 0) { int prev = v[k].prevIdx; int next = v[k].nextIdx; if (prev!=-1) { v[prev].nextIdx = next; } if (next != -1) { v[next].prevIdx = prev; } return; } if (aCase == 2) { if (v[k].val == 1) { // to jest nowa wartosc, wiec trzeba policzyc jej prev i Next if (providedPrev > 0) { int next = k + providedPrev; int prev = v[next].prevIdx; if (prev != -1) v[prev].nextIdx = k; v[k].nextIdx = next; v[k].prevIdx = prev; v[next].prevIdx = k; } if (providedPrev < 0) { int prev = k + providedPrev; int next = v[prev].nextIdx; v[prev].nextIdx = k; v[k].nextIdx = next; v[k].prevIdx = prev; if (next != -1) v[next].prevIdx = k; } return; } int prev = v[k].prevIdx; int next = v[k].nextIdx; if (prev != -1 && v[prev].val == 0) v[k].prevIdx = v[prev].prevIdx; if (next != -1 && v[next].val == 0) v[k].nextIdx = v[next].nextIdx; } } vector<LL> calculateAnswerToQueries(vector<RemappedValue> &rowSums, vector<RemappedValue> &colSums, vector<Query> &queries) { vector<LL> res; LL n = rowSums.size(); LL Xcnt = 0; LL Xcnt_assert = 0; // always calulate first answer for (int i=0; i < n; i++) { LL rs = rowSums[i].val; LL cs = colSums[i].val; Xcnt += rs; Xcnt_assert += cs; } if (Xcnt != Xcnt_assert) printf("error: sum in rows and columns should be the same!!\n"); //DBG(printf("Xcnt=%lld\n", Xcnt)); sort(colSums.begin(), colSums.end()); sort(rowSums.begin(), rowSums.end()); vector<int> remapColSums, remapRowSums; remapColSums.resize(n); remapRowSums.resize(n); REP(i,n) remapRowSums[rowSums[i].originalIdx] = i; REP(j,n) remapColSums[colSums[j].originalIdx] = j; vector<Zajetosc> ileWierszyOZajetosci = calculateZajetosc(n, rowSums); vector<Zajetosc> ileKolumnOZajetosci = calculateZajetosc(n, colSums); int minNonEmptyRowSum = 0; int minNonEmptyColSum = 0; REP(i,n) if (ileWierszyOZajetosci[i].val) { minNonEmptyRowSum = i; break; } REP(j,n) if (ileKolumnOZajetosci[j].val) { minNonEmptyColSum = j; break; } //res.emplace_back(ileMozliwychRuchow(n, Xcnt, rowSums, colSums)); res.emplace_back(ileMozliwychRuchowFaster(n, Xcnt, ileWierszyOZajetosci, ileKolumnOZajetosci, minNonEmptyRowSum, minNonEmptyColSum, false)); for (Query &query : queries) { DBG(printf("processng query %d\n", query.index)); int rowIdx = remapRowSums[query.p.row]; int colIdx = remapColSums[query.p.col]; // we flip from 0 to 1 int ileWWierszu = rowSums[rowIdx].val; int ileWKolumnie = colSums[colIdx].val; int lastIleWWierszu = ileWWierszu; int lastIleWKolumnie = ileWKolumnie; int prev = -30; if (query.initialValueAtPos == 0) { ++rowSums[rowIdx].val; ++colSums[colIdx].val; ++Xcnt; ++ileWWierszu; ++ileWKolumnie; prev = -1; } else { // flip from 1 to 0 --rowSums[rowIdx].val; --colSums[colIdx].val; --Xcnt; --ileWWierszu; --ileWKolumnie; prev = 1; } ++ileWierszyOZajetosci[ileWWierszu].val; ++ileKolumnOZajetosci[ileWKolumnie].val; updateZajetoscPtr(ileWierszyOZajetosci, ileWWierszu, 2, prev); updateZajetoscPtr(ileKolumnOZajetosci, ileWKolumnie, 2, prev); --ileWierszyOZajetosci[lastIleWWierszu].val; --ileKolumnOZajetosci[lastIleWKolumnie].val; updateZajetoscPtr(ileWierszyOZajetosci, lastIleWWierszu, 1, 30); updateZajetoscPtr(ileKolumnOZajetosci, lastIleWKolumnie, 1, 30); if (minNonEmptyRowSum - 1 >= 0 && ileWierszyOZajetosci[minNonEmptyRowSum - 1].val > 0) { minNonEmptyRowSum--; } if (minNonEmptyColSum - 1 >= 0 && ileKolumnOZajetosci[minNonEmptyColSum - 1].val > 0) { minNonEmptyColSum--; } if (ileWierszyOZajetosci[minNonEmptyRowSum].val == 0) minNonEmptyRowSum++; if (ileKolumnOZajetosci[minNonEmptyColSum].val == 0) minNonEmptyColSum++; debugValidateRange(n, rowSums[rowIdx].val); debugValidateRange(n, colSums[colIdx].val); // DEBUG: /*sort(colSums.begin(), colSums.end()); sort(rowSums.begin(), rowSums.end()); REP(i,n) remapRowSums[rowSums[i].originalIdx] = i; REP(j,n) remapColSums[colSums[j].originalIdx] = j; DBG(printf("Row sums: ")); DBG(print_vec(rowSums)); DBG(printf("Col sums: ")); DBG(print_vec(colSums));*/ // END OF DEBUG //res.emplace_back(ileMozliwychRuchow(n, Xcnt, rowSums, colSums)); res.emplace_back(ileMozliwychRuchowFaster(n, Xcnt, ileWierszyOZajetosci, ileKolumnOZajetosci, minNonEmptyRowSum, minNonEmptyColSum, true)); } return res; } vector<LL> solve(int n, vector<Rect> &updates, vector<Query> &kingsRequests) { //selftest(); vector<LL> res; vector<vector<pair<pair<int, int>, int> > > intervals; intervals.resize(n); for (auto &u : updates) { pair<int, int> rg = make_pair(u.topLeft.col, u.bottomRight.col); intervals[u.topLeft.row].emplace_back(make_pair(rg, 1)); // open intervals[u.bottomRight.row].emplace_back(make_pair(rg, 2)); // close } vector<RemappedValue> rowSums = calculateSums(n, intervals, kingsRequests, true); /*REP(i, kingsRequests.size()) { Query &q = kingsRequests[i]; DBG(printf("Q{idx:%d,pos=(%d,%d),bit:%d}\n", q.index, q.p.row, q.p.col, q.initialValueAtPos)); }*/ intervals.clear(); intervals.resize(n); for (auto &u : updates) { pair<int, int> rg = make_pair(u.topLeft.row, u.bottomRight.row); intervals[u.topLeft.col].emplace_back(make_pair(rg, 1)); // open intervals[u.bottomRight.col].emplace_back(make_pair(rg, 2)); // close } vector<RemappedValue> colSums = calculateSums(n, intervals, kingsRequests, false); return calculateAnswerToQueries(rowSums, colSums, kingsRequests); } int main() { int n,m,q; int rc = scanf("%d%d%d", &n, &m, &q); if (rc < 0) { return 0; } vector<Rect> updates; for (int i=0; i < m; i++) { int x1, y1, x2, y2; rc = scanf("%d%d%d%d", &x1, &y1, &x2, &y2); if (rc < 0) { return 0; } updates.emplace_back(Rect(Pos(x1-1, y1-1), Pos(x2-1, y2-1))); } vector<Query> kingsRequests; for (int i=0; i < q; i++) { int x,y; rc = scanf("%d%d", &x, &y); if (rc < 0) { return 0; } kingsRequests.emplace_back(Query(Pos(x-1, y-1),i, -1)); } vector<LL> res = solve(n, updates, kingsRequests); for (int i=0; i < int(res.size()); i++) { printf("%lld\n", res[i]); } return 0; } /* Brute: D:\devel\projects\pa2020\bal>a.exe < forum/small956.in Update 4 0 15 14 Update 8 8 10 9 Update 14 14 17 14 Update 8 4 10 4 Update 3 2 3 4 Update 14 3 14 6 Update 7 2 7 7 Update 3 15 6 17 Update 7 14 9 17 Update 4 14 8 17 Na poczatku: oooooooooooooooooo oooooooooooooooooo oooooooooooooooooo ooxxxooooooooooxxx xxxxxxxxxxxxxxoooo xxxxxxxxxxxxxxoooo xxxxxxxxxxxxxxoooo xxooooooxxxxxxxooo↔ xxxxoxxxooxxxxxooo xxxxoxxxooxxxxoxxx xxxxoxxxooxxxxxooo xxxxxxxxxxxxxxxooo xxxxxxxxxxxxxxxooo xxxxxxxxxxxxxxxooo xxxooooxxxxxxxoooo xxxxxxxxxxxxxxoooo ooooooooooooooxooo ooooooooooooooxooo Row sums: 0 0 0 6 14 14 14 9 12 14 12 15 15 15 10 14 1 1 Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 12 12 8 2 2 2 Xcnt=166 blocked=0 D:\devel\projects\pa2020\bal>a.exe < forum/small956.in Row sums: 0 0 0 6 14 14 14 9 12 14 12 15 15 15 10 14 1 1 Queries: Q{idx:0,pos=(10,12),bit:1} Q{idx:1,pos=(0,14),bit:0} Q{idx:2,pos=(10,15),bit:0} Q{idx:3,pos=(17,12),bit:0} Q{idx:4,pos=(0,16),bit:0} Q{idx:5,pos=(7,17),bit:0} Q{idx:6,pos=(12,2),bit:1} Q{idx:7,pos=(13,13),bit:1} Q{idx:8,pos=(9,9),bit:0} Q{idx:9,pos=(13,5),bit:1} Q{idx:10,pos=(9,14),bit:0} Q{idx:11,pos=(17,14),bit:1} Q{idx:12,pos=(3,5),bit:0} Q{idx:13,pos=(7,4),bit:0} Q{idx:14,pos=(8,2),bit:1} Q{idx:15,pos=(2,9),bit:0} Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 12 12 8 2 2 2 Xcnt=166 blockedXes=0 blockedEmptys=0 wolnych=158 Xcnt=166 processng query 0 Row sums: 0 0 0 6 14 14 14 9 12 14 11 15 15 15 10 14 1 1 Col sums: 12 12 12 11 8 10 10 11 9 9 12 12 11 12 8 2 2 2 i * j - suma(0,i) + suma(0,j) */ |