제출 #1028809

#제출 시각아이디문제언어결과실행 시간메모리
1028809onbertRectangles (IOI19_rect)C++17
72 / 100
3853 ms1048576 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; #define ll long long struct range { int r, mx; }; bool cmp0(range &a, range &b) {return a.r > b.r;} bool cmp1(range &a, range &b) {return a.mx > b.mx;} const int maxn = 2505, INF = 1e9; int n, m; vector<vector<pair<int,int>>> pos[2][maxn]; vector<range> start[2][maxn][maxn]; int fen[maxn]; void update(int id, int val) { while (id<maxn) { fen[id] += val; id += (id & -id); } } int qry(int id) { int val = 0; while (id >= 1) { val += fen[id]; id -= (id & -id); } return val; } long long count_rectangles(vector<vector<int32_t>> a) { n = a.size(), m = a[0].size(); for (int i=0;i<max(n, m);i++) pos[0][i].resize(max(n, m) - i), pos[1][i].resize(max(n, m) - i); vector<pair<int,int>> cur; vector<int> temp; set<int> s; for (int i=0;i<n;i++) { cur.clear(); for (int j=0;j<m;j++) cur.push_back({a[i][j], j}); sort(cur.rbegin(), cur.rend()); s.clear(); s.insert(-1); s.insert(INF); temp.clear(); for (int j=0;j<m;j++) { auto [val, id] = cur[j]; if (j>0 && val!=cur[j-1].first) { for (int x:temp) s.insert(x); temp.clear(); } auto it = s.upper_bound(id); int l = *prev(it), r = *it; if (l!=-1 && r!=INF) { l++, r--; if (pos[0][l][r-l].size()==0 || pos[0][l][r-l].back().first!=i) { pos[0][l][r-l].push_back({i, -1}); start[0][i][l].push_back({r, -1}); } } temp.push_back(id); } } for (int j=0;j<m;j++) { cur.clear(); for (int i=0;i<n;i++) cur.push_back({a[i][j], i}); sort(cur.rbegin(), cur.rend()); s.clear(); s.insert(-1); s.insert(INF); temp.clear(); for (int i=0;i<n;i++) { auto [val, id] = cur[i]; if (i>0 && val!=cur[i-1].first) { for (int x:temp) s.insert(x); temp.clear(); } auto it = s.upper_bound(id); int l = *prev(it), r = *it; if (l!=-1 && r!=INF) { l++, r--; if (pos[1][l][r-l].size()==0 || pos[1][l][r-l].back().first!=j) { pos[1][l][r-l].push_back({j, -1}); start[1][l][j].push_back({r, -1}); } } temp.push_back(id); } } for (int I=0;I<=1;I++) { int nn = m; if (I==1) nn = n; for (int l=0;l<nn;l++) for (int r=l;r<nn;r++) { sort(pos[I][l][r-l].begin(), pos[I][l][r-l].end()); int sz = pos[I][l][r-l].size(); for (int i=sz-1;i>=0;i--) { if (i==sz-1 || pos[I][l][r-l][i+1].first!=pos[I][l][r-l][i].first+1) pos[I][l][r-l][i].second = pos[I][l][r-l][i].first; else pos[I][l][r-l][i].second = pos[I][l][r-l][i+1].second; } } } for (int I=0;I<=1;I++) { for (int i=0;i<n;i++) for (int j=0;j<m;j++) { for (auto &[r, mx]:start[I][i][j]) { int x = j, y = i; if (I==1) x = i, y = j; mx = (*lower_bound(pos[I][x][r-x].begin(), pos[I][x][r-x].end(), make_pair(y, -INF))).second; } } } ll ans = 0; vector<int> LOG; for (int i=0;i<n;i++) for (int j=0;j<m;j++) { sort(start[0][i][j].begin(), start[0][i][j].end(), cmp0); sort(start[1][i][j].begin(), start[1][i][j].end(), cmp1); int pt = -1; LOG.clear(); for (auto [r, mx]:start[0][i][j]) { while (pt+1 < start[1][i][j].size() && start[1][i][j][pt+1].mx >= r) { pt++; update(start[1][i][j][pt].r, 1); LOG.push_back(start[1][i][j][pt].r); } ans += qry(mx); } for (int x:LOG) update(x, -1); } return ans; }

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

rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:116:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<range>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  116 |             while (pt+1 < start[1][i][j].size() && start[1][i][j][pt+1].mx >= r) {
      |                    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...