QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#140215 | #2672. Rectangles | minhcool# | 0 | 4496ms | 163340kb | C++14 | 3.9kb | 2023-08-15 14:55:07 | 2024-07-04 01:43:55 |
Judging History
answer
//#define local
#ifndef local
#include "rect.h"
#endif
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef pair<ii, ii> iiii;
const ll N = 2505 + 5;
const ll oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
ll rnd(ll l, ll r){
ll temp = rng() % (r - l + 1);
return abs(temp) + l;
}
ll n, m, a[N][N];
ll mxr[N][N], mxl[N][N], mxd[N][N], mxu[N][N];
vector<ii> vc;
vector<ll> events[N];
ll minr[N], maxl[N];
ll bit[N];
void upd(ll id, ll val){
for(; id <= m; id += id & -id) bit[id] += val;
}
ll get(ll id){
ll ans = 0;
for(; id; id -= id & -id) ans += bit[id];
return ans;
}
ll count_rectangles(vector<vector<int>> arr){
n = arr.size(), m = arr[0].size();
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++) a[i][j] = arr[i][j];
}
for(ll i = 0; i < n; i++){
stack<ll> stk;
stk.push(-1);
for(ll j = 0; j < m; j++){
while(stk.top() >= 0 && a[i][stk.top()] < a[i][j]) stk.pop();
mxl[i][j] = stk.top() + 1;
stk.push(j);
}
}
for(ll i = 0; i < n; i++){
stack<ll> stk;
stk.push(-1);
for(ll j = 0; j < m; j++){
while(stk.top() >= 0 && a[i][stk.top()] < a[i][j]) stk.pop();
mxl[i][j] = stk.top() + 1;
stk.push(j);
}
}
for(ll i = 0; i < n; i++){
stack<ll> stk;
stk.push(m);
for(ll j = m - 1; j >= 0; j--){
while(stk.top() < m && a[i][stk.top()] < a[i][j]) stk.pop();
mxr[i][j] = stk.top() - 1;
stk.push(j);
}
}
for(ll i = 0; i < m; i++){
stack<ll> stk;
stk.push(-1);
for(ll j = 0; j < n; j++){
while(stk.top() >= 0 && a[stk.top()][i] < a[j][i]) stk.pop();
mxu[j][i] = stk.top() + 1;
stk.push(j);
}
}
for(ll i = 0; i < m; i++){
stack<ll> stk;
stk.push(n);
for(ll j = n - 1; j >= 0; j--){
while(stk.top() < n && a[stk.top()][i] < a[j][i]) stk.pop();
mxd[j][i] = stk.top() - 1;
stk.push(j);
}
}
for(ll i = 0; i < n; i++){
//for(ll j = 0; j < m; j++) cout << i << " " << j << " " << mxr[i][j] << " " << mxl[i][j] << " " << mxu[i][j] << " " << mxd[i][j] << "\n";
}
ll answer = 0;
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++){
minr[j] = oo, maxl[j] = -oo;
}
for(ll j = i + 2; j < n; j++){
for(ll k = 0; k < m; k++){
minr[k] = min(minr[k], mxr[j - 1][k]);
maxl[k] = max(maxl[k], mxl[j - 1][k]);
}
vc.clear();
ll lst = -oo;
for(ll k = 1; k < m; k++){
if(mxd[i][k] >= j - 1 && mxu[j][k] <= i + 1 && k < (m - 1)){
if(lst == -oo) lst = k;
}
else{
if(lst >= 0) vc.pb({lst, k - 1});
lst = -oo;
}
}
for(ll k = 0; k <= m; k++){
events[k].clear();
bit[k] = 0;
}
for(auto it : vc){
//cout << i << " " << j << " " << it.fi << " " << it.se << "\n";
//cout << minr[it.fi - 1] << " " << maxl[it.fi + 1] << "\n";
//for(ll k = it.fi - 1; k < it.se; k++) events[min(it.se, minr[k]) + 1];
for(ll k = it.fi; k <= it.se; k++){
upd(k, 1);
events[min(it.se, minr[k - 1]) + 1].pb(k);
for(auto it : events[k]) upd(it, -1);
//cout << maxl[k + 1] << " " <<
answer += get(m) - get(max(0LL, maxl[k + 1] - 1));
//cout << min(it.se, minr[k - 1]) + 1 << " " << maxl[k + 1] << "\n";
}
//cout << answer << "\n";
}
}
}
return answer;
}
#ifdef local
void process(){
ll n, m;
cin >> n >> m;
vector<vector<int>> board;
board.resize(n);
for(ll i = 0; i < n; i++) board[i].resize(m);
for(ll i = 0; i < n; i++){
for(ll j = 0; j < m; j++) cin >> board[i][j];
}
cout << count_rectangles(board) << "\n";
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
freopen("kek.inp", "r", stdin);
freopen("kek.out", "w", stdout);
process();
}
#endif
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 0ms
memory: 22384kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 3996 3689 3664 3657 3646 3630 3621 3619 3609 3604 3601 3598 3584 3581 3574 3561 3554 3543 3537 3531 3522 3519 3505 3500 3498 3492 3476 3467 3460 3994 3993 3458 3451 3440 3431 3420 3395 3346 3333 3282 3268 3261 3241 3204 3168 3121 3103 3083 3076 2923 2872 28...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 784
result:
ok 3 lines
Test #2:
score: 8
Accepted
time: 0ms
memory: 12204kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 6996495 6421812 6403903 6382663 6362922 6334993 6329757 6315983 6278578 6262778 6254104 6244987 6232172 6226987 6194797 6176457 6167900 6140865 6123884 6116295 6101556 6079188 6068604 6049308 6034911 6034041 6015464 6004614 5992300 6995512 6987555 5978527 5...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 784
result:
ok 3 lines
Test #3:
score: 8
Accepted
time: 2ms
memory: 12200kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 12330 11301 11283 11257 11240 11194 11170 11135 11116 11095 11085 11048 11000 10972 10914 10909 10897 10877 10835 10823 10789 10781 10769 10745 10708 10690 10665 10661 10645 12329 12326 10635 10633 10590 10557 10542 10513 10491 10418 10406 10096 10086 9930 ...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 784
result:
ok 3 lines
Test #4:
score: 8
Accepted
time: 2ms
memory: 16184kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 0
result:
ok 3 lines
Test #5:
score: 0
Wrong Answer
time: 2ms
memory: 12072kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 30 30 1023589 2780022 3479561 3782160 3952727 450470 3945264 2170843 3225056 1786041 1389306 1419234 3915988 520009 1251948 104723 1856504 3637799 1807024 2170722 2803041 2964655 2003819 1048641 3939016 2826494 3085605 1000286 3022731 1498648 3779781 3073573 7294...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 364
result:
wrong answer 3rd lines differ - expected: '268', found: '364'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Wrong Answer
Test #53:
score: 10
Accepted
time: 2ms
memory: 12500kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 2500 3999533 3994407 3992243 3991052 3990430 3988819 3987546 3985557 3983808 3983398 3982565 3981632 3981437 3979888 3979428 3978697 3978033 3975044 3973166 3972565 3971499 3970538 3969576 3969014 3968513 3968337 3966950 3965168 3964140 3963957 3962080 3961829 ...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 2498
result:
ok 3 lines
Test #54:
score: 10
Accepted
time: 0ms
memory: 12180kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 2123 3999178 3994918 3993586 3990671 3989261 3988091 3985537 3984649 3983635 3982639 3981319 3980647 3979462 3978557 3977387 3976784 3975890 3975694 3975367 3975193 3973331 3971593 3970332 3969892 3968052 3967213 3966031 3963229 3963001 3962625 3961725 3959892 ...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 2121
result:
ok 3 lines
Test #55:
score: 10
Accepted
time: 0ms
memory: 12188kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 2500 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 0
result:
ok 3 lines
Test #56:
score: 10
Accepted
time: 0ms
memory: 12024kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 1 2 0 3
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 0
result:
ok 3 lines
Test #57:
score: 0
Wrong Answer
time: 0ms
memory: 14208kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 3 2500 3073920 3547280 2578996 515881 1457637 3747191 3335718 1093356 188596 2501359 1707005 923685 1254329 1274578 2451887 1948214 3495100 706306 2036295 3924470 2870740 2253399 2559834 2223853 3524040 448754 2838433 2573451 1627516 2712253 1015735 1941089 29861...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 2077
result:
wrong answer 3rd lines differ - expected: '688', found: '2077'
Subtask #6:
score: 0
Wrong Answer
Test #64:
score: 13
Accepted
time: 0ms
memory: 11972kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 10 10 1 1 0 0 1 0 0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 0 0 1 1 1 1 0 0 1 0 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0 1 1 0
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 2
result:
ok 3 lines
Test #65:
score: 0
Wrong Answer
time: 4496ms
memory: 163340kb
input:
8d9a74d5-4c4b-4437-9c49-114beaeb8f1a 1234 2321 0 0 0 1 0 0 0 1 0 0 0 1 1 1 0 1 1 1 0 0 0 0 1 1 1 1 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 1 1 0 1 1 1 1 1 1 1 1 0 0 0 1 0 0 1 1 0 1 1 1 1 1 0 0 1 1 1 1 0 1 1 0 0 1 0 0 1 0 1 0 0 1 0 1 0 0 1 1 0 0 1 0 0 0 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 1 1 1 0 1 1...
output:
907404fa-efbb-4a2c-83b8-4c377409c80c OK 125923
result:
wrong answer 3rd lines differ - expected: '116238', found: '125923'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%