제출 #264766

#제출 시각아이디문제언어결과실행 시간메모리
264766BruteforcemanRectangles (IOI19_rect)C++17
72 / 100
5042 ms752912 KiB
#include "bits/stdc++.h" #include "rect.h" using namespace std; const int maxn = 2505; struct rect { int i, j; int l, r; rect (int i, int j, int l, int r) : i(i), j(j), l(l), r(r) {} rect () {} }; vector <pair <int, int>> ver[maxn][maxn], hor[maxn][maxn]; int t[maxn]; vector <int> v[maxn]; void getLines(vector<vector<int>> &a, vector <rect> &vert) { int n = a.size(); int m = a.front().size(); for(int i = 0; i < m; i++) v[i].clear(); set <int> last, aux; vector <int> arr (n); for(int i = 0; i < n; i++) { last.clear(); fill(arr.begin(), arr.end(), -1); for(int j = 0; j < m; j++) { aux.clear(); for(int k = int(v[j].size()) - 1; k >= 0; k--) { aux.insert(v[j][k]); if(a[v[j][k]][j] >= a[i][j]) break; } while(!v[j].empty() && a[v[j].back()][j] <= a[i][j]) { v[j].pop_back(); } v[j].push_back(i); for(int k : last) { if(aux.find(k) == aux.end()) { if(k < i - 1) vert.emplace_back(k, i, arr[k], j - 1); arr[k] = -1; } } for(int k : aux) { if(arr[k] == -1) arr[k] = j; } last = aux; } for(int k : last) { if(k < i - 1) vert.emplace_back(k, i, arr[k], m - 1); } } } void rotate(vector <vector <int>> &a) { int n = a.size(); int m = a.front().size(); vector <vector <int>> b (m, vector <int> (n, 0)); for(int i = 0; i < m; i++) { for(int j = 0; j < n; j++) { b[i][j] = a[j][i]; } } a = b; } void update(int x, int val) { x += 1; for(int i = x; i < maxn; i += i & (-i)) { t[i] += val; } } int query(int x) { x += 1; int sum = 0; for(int i = x; i > 0; i -= i & (-i)) { sum += t[i]; } return sum; } long long solve(int i, int j) { long long ans = 0; auto cmp = [&] (const pair <int, int> &i, const pair <int, int> j) { return i.second < j.second; }; sort(hor[i][j].begin(), hor[i][j].end(), cmp); sort(ver[i][j].begin(), ver[i][j].end(), cmp); int pt = 0; for(auto y : ver[i][j]) { while(pt < hor[i][j].size() && hor[i][j][pt].second <= y.second) { update(hor[i][j][pt].first, 1); ++pt; } ans += query(2500) - query(y.first - 1); } for(int y = 0; y < pt; y++) update(hor[i][j][y].first, -1); return ans; } long long count_rectangles(vector <vector <int>> a) { int n = a.size(); int m = a.front().size(); vector <rect> h, v; getLines(a, h); rotate(a); getLines(a, v); for(auto &x : v) { int aux = x.l; x.l = max(0, x.l - 1); x.r = min(n - 1, x.r + 1); for(int i = x.l; i <= x.r; i++) { ver[i][x.j].emplace_back(x.l, x.i); } } for(auto &x : h) { int aux = x.l; x.l = max(0, x.l - 1); x.r = min(m - 1, x.r + 1); for(int i = x.l; i <= x.r; i++) { hor[x.j][i].emplace_back(x.i, x.l); } } long long ans = 0; for(int i = 0; i < n; i++) { for(int j = 0; j < m; j++) { ans += solve(i, j); } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

rect.cpp: In function 'long long int solve(int, int)':
rect.cpp:84:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     while(pt < hor[i][j].size() && hor[i][j][pt].second <= y.second) {
      |           ~~~^~~~~~~~~~~~~~~~~~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:101:9: warning: unused variable 'aux' [-Wunused-variable]
  101 |     int aux = x.l;
      |         ^~~
rect.cpp:109:9: warning: unused variable 'aux' [-Wunused-variable]
  109 |     int aux = x.l;
      |         ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...