Блог пользователя mostafaagaan

Автор mostafaagaan, история, 3 недели назад, По-английски

the problem is at first complicated, but once you hold the concept of 2d array prefix and 2d difference array you will find it simple, first you have to swap coordinates such that x1<x2 and y1<y2 and after that you construct the difference array such that each rectangle is filled with a bunch of nonzero numbers , then you construct the 2d prefix array, finally we count all zero's in the prefix where 0 means not surrounded by a rectangle and any non zero number indicates the opposite

ll tc = 1; void solve() { read(w); read(h); read(n); vector<vector>diffArr(w+1,vector(h+1,0)); vector<vector>prefix(w+1,vector(h+1,0)); while(n--) { read(x1);read(y1);read(x2);read(y2); if (x1 > x2)swap(x1, x2); if (y1 > y2)swap(y1, y2); diffArr[x1-1][y1-1] += 1; diffArr[x2][y1-1] -= 1; diffArr[x1-1][y2] -= 1; diffArr[x2][y2] += 1; } up(i,1,w+1){ up(j,1,h+1){ prefix[i][j]=diffArr[i-1][j-1]+prefix[i-1][j]+prefix[i][j-1]-prefix[i-1][j-1]; } } ll cnt{}; up(i,1,w+1){ up(j,1,h+1){ if(prefix[i][j]==0)cnt++; } } cout<<cnt<<el; }

int main() { if(tc){much(t);} else {once;} return 0; }

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
3 недели назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by mostafaagaan (previous revision, new revision, compare).