This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> tree;
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = x;
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
int querry(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return 0;
if (rl == ql && rr == qr) {
return tree[v];
}
int rm = (rl + rr) / 2;
return max(querry(v*2, rl, rm, ql, min(qr, rm)), querry(v*2+1, rm+1, rr, max(rm+1, ql), qr));
}
long long count_rectangles(std::vector<std::vector<int> > a) {
vector<bool> topBottom;
tree.assign(a[1].size()*4, 0);
int res = 0;
for (int i = 0; i<a[1].size(); i++) {
topBottom.push_back(a[1][i] < a[0][i] && a[1][i] < a[2][i]);
update(1, 0, a[1].size()-1, i, a[1][i]);
}
for (int i = 1; i<a[1].size()-1; i++) {
for (int j = i; j<a[1].size()-1; j++) {
if (querry(1, 0, a[1].size()-1, i, j) < min(a[1][i-1], a[1][j+1])) { res++;}
}
}
return res;
}
Compilation message (stderr)
rect.cpp: In function 'long long int count_rectangles(std::vector<std::vector<int> >)':
rect.cpp:43:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for (int i = 0; i<a[1].size(); i++) {
| ~^~~~~~~~~~~~
rect.cpp:48:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
48 | for (int i = 1; i<a[1].size()-1; i++) {
| ~^~~~~~~~~~~~~~
rect.cpp:49:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int j = i; j<a[1].size()-1; j++) {
| ~^~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |