Submission #146020

#TimeUsernameProblemLanguageResultExecution timeMemory
146020jwvg0425Rectangles (IOI19_rect)C++17
15 / 100
86 ms49028 KiB
#include "rect.h" #include <stdio.h> #include <vector> #include <queue> #include <algorithm> #include <iostream> #include <string> #include <bitset> #include <map> #include <set> #include <tuple> #include <string.h> #include <math.h> #include <random> #include <functional> #include <assert.h> #include <math.h> #include <stack> #define all(x) (x).begin(), (x).end() #define xx first #define yy second #define MAXL 105 using namespace std; using i64 = long long int; using ii = pair<int, int>; using ii64 = pair<i64, i64>; class FenwickTree { public: FenwickTree(int k) { data.resize(k); } i64 sum(int n) { i64 ans = 0; while (n > 0) { ans += data[n]; n -= (n & -n); } return ans; } void add(int n, i64 num) { while (n < data.size()) { data[n] += num; n += (n & -n); } } private: vector<i64> data; }; vector<int> rlen[MAXL][MAXL]; vector<int> dlen[MAXL][MAXL]; // (구간 길이, 반대편 확장 가능 길이) vector<ii> rseg[MAXL][MAXL]; vector<ii> dseg[MAXL][MAXL]; long long count_rectangles(vector<vector<int>> a) { i64 ans = 0; int n = a.size(); int m = a[0].size(); for (int x = 0; x < n; x++) { stack<int> s; for (int y = 0; y < m; y++) { while (!s.empty() && a[x][s.top()] <= a[x][y]) { int l = y - s.top() - 1; if (l > 0) rlen[x][s.top()].push_back(l); s.pop(); } s.push(y); } stack<int> s2; for (int y = m - 1; y >= 0; y--) { while (!s2.empty() && a[x][s2.top()] <= a[x][y]) { int l = s2.top() - y - 1; if (a[x][s2.top()] != a[x][y] && l > 0) rlen[x][y].push_back(l); s2.pop(); } s2.push(y); } } for (int y = 0; y < m; y++) { stack<int> s; for (int x = 0; x < n; x++) { while (!s.empty() && a[s.top()][y] <= a[x][y]) { int l = x - s.top() - 1; if (l > 0) dlen[s.top()][y].push_back(l); s.pop(); } s.push(x); } stack<int> s2; for (int x = n - 1; x >= 0; x--) { while (!s2.empty() && a[s2.top()][y] <= a[x][y]) { int l = s2.top() - x - 1; if (a[s2.top()][y] != a[x][y] && l > 0) dlen[x][y].push_back(l); s2.pop(); } s2.push(x); } } for (int x = 0; x < n; x++) { for (int y = 0; y < m; y++) { sort(all(rlen[x][y])); sort(all(dlen[x][y])); } } for (int y = 0; y < m; y++) { for (auto& rv : rlen[n - 1][y]) rseg[n - 1][y].emplace_back(rv, 1); for (int x = n - 2; x >= 0; x--) { for (auto& rv : rlen[x][y]) { auto iter = lower_bound(all(rseg[x + 1][y]), ii(rv, 0)); int l = 1; if (iter != rseg[x + 1][y].end() && iter->xx == rv) l = iter->yy + 1; rseg[x][y].emplace_back(rv, l); } } } for (int x = 0; x < n; x++) { for (auto& dv : dlen[x][m - 1]) dseg[x][m - 1].emplace_back(dv, 1); for (int y = m - 2; y >= 0; y--) { for (auto& dv : dlen[x][y]) { auto iter = lower_bound(all(dseg[x][y + 1]), ii(dv, 0)); int l = 1; if (iter != dseg[x][y + 1].end() && iter->xx == dv) l = iter->yy + 1; dseg[x][y].emplace_back(dv, l); } } } for (int x = 0; x < n; x++) { for (int y = 0; y < m; y++) { sort(all(rseg[x][y]), [](const ii& l, const ii& r) { return l.yy < r.yy; }); sort(all(dseg[x][y])); } } FenwickTree tree(2505); for (int x = 1; x < n - 1; x++) { for (int y = 1; y < m - 1; y++) { int didx = 0; for (auto& ri : rseg[x][y - 1]) { while (didx < dseg[x - 1][y].size() && dseg[x - 1][y][didx].xx <= ri.yy) { tree.add(dseg[x - 1][y][didx].yy, 1); didx++; } ans += tree.sum(2503) - tree.sum(ri.xx - 1); } for (int dx = 0; dx < didx; dx++) tree.add(dseg[x - 1][y][dx].yy, -1); } } return ans; }

Compilation message (stderr)

rect.cpp: In member function 'void FenwickTree::add(int, i64)':
rect.cpp:53:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   while (n < data.size())
          ~~^~~~~~~~~~~~~
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:212:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (didx < dseg[x - 1][y].size() && dseg[x - 1][y][didx].xx <= ri.yy)
            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#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...