Submission #667454

#TimeUsernameProblemLanguageResultExecution timeMemory
667454flappybirdRectangles (IOI19_rect)C++17
59 / 100
1756 ms1048576 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define MAX 2510 int N, M; vector<short> axis[2][MAX][MAX]; vector<short> endp[2][MAX][MAX]; int ans = 0; void chk(short r1, short c1, short r2, short c2) { if (r1 > r2 || c1 > c2 || r2 >= N - 1 || c2 >= M - 1 || r1 <= 0 || c1 <= 0) return; short ind1, ind2; ind1 = lower_bound(axis[0][r1][r2].begin(), axis[0][r1][r2].end(), c1) - axis[0][r1][r2].begin(); ind2 = lower_bound(axis[0][r1][r2].begin(), axis[0][r1][r2].end(), c2) - axis[0][r1][r2].begin(); if (ind1 >= axis[0][r1][r2].size()) return; if (ind2 >= axis[0][r1][r2].size()) return; if (c1 != axis[0][r1][r2][ind1]) return; if (c2 != axis[0][r1][r2][ind2]) return; if (c2 - c1 != ind2 - ind1) return; ind1 = lower_bound(axis[1][c1][c2].begin(), axis[1][c1][c2].end(), r1) - axis[1][c1][c2].begin(); ind2 = lower_bound(axis[1][c1][c2].begin(), axis[1][c1][c2].end(), r2) - axis[1][c1][c2].begin(); if (ind1 >= axis[1][c1][c2].size()) return; if (ind2 >= axis[1][c1][c2].size()) return; if (r1 != axis[1][c1][c2][ind1]) return; if (r2 != axis[1][c1][c2][ind2]) return; if (r2 - r1 != ind2 - ind1) return; ans++; } long long count_rectangles(std::vector<std::vector<int> > A) { N = A.size(); M = A[0].size(); int i, j; for (i = 0; i < N; i++) { vector<pii> st; for (j = 0; j < M; j++) { int cc = 1; while (st.size() && st.back().first <= A[i][j]) { if (st.back().first == A[i][j]) cc = 0; axis[1][st.back().second + 1][j - 1].push_back(i); endp[1][i][st.back().second + 1].push_back(j - 1); st.pop_back(); } if (cc && st.size()) { axis[1][st.back().second + 1][j - 1].push_back(i); endp[1][i][st.back().second + 1].push_back(j - 1); } st.emplace_back(A[i][j], j); } } for (i = 0; i < M; i++) { vector<pii> st; for (j = 0; j < N; j++) { int cc = 1; while (st.size() && st.back().first <= A[j][i]) { if (st.back().first == A[j][i]) cc = 0; axis[0][st.back().second + 1][j - 1].push_back(i); endp[0][st.back().second + 1][i].push_back(j - 1); st.pop_back(); } if (cc&&st.size()) { axis[0][st.back().second + 1][j - 1].push_back(i); endp[0][st.back().second + 1][i].push_back(j - 1); } st.emplace_back(A[j][i], j); } } for (i = 1; i < N - 1; i++) for (j = 1; j < M - 1; j++) for (auto ii : endp[0][i][j]) for (auto jj : endp[1][i][j]) chk(i, j, ii, jj); return ans; }

Compilation message (stderr)

rect.cpp: In function 'void chk(short int, short int, short int, short int)':
rect.cpp:16:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  if (ind1 >= axis[0][r1][r2].size()) return;
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:17:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   17 |  if (ind2 >= axis[0][r1][r2].size()) return;
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:23:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   23 |  if (ind1 >= axis[1][c1][c2].size()) return;
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
rect.cpp:24:11: warning: comparison of integer expressions of different signedness: 'short int' and 'std::vector<short int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |  if (ind2 >= axis[1][c1][c2].size()) return;
      |      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...