QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#487549 | #2672. Rectangles | Dan4Life | 0 | 66ms | 301220kb | C++23 | 3.1kb | 2024-07-22 23:30:59 | 2024-07-22 23:30:59 |
Judging History
answer
#include "rect.h"
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) begin(a),end(a)
using ll = long long;
using vi = vector<int>;
using ar2 = array<int,2>;
const int mxN = 2502;
int n, m;
int grid[mxN][mxN], pref[mxN][mxN], fen[mxN][mxN];
vector<int> row[mxN][mxN], col[mxN][mxN];
set<pair<int,int>> found[mxN][mxN];
deque<ar2> lines[mxN];
vector<int> grid2[mxN];
struct Fenwick2D{
int fen[mxN][mxN];
void init(int n, int m){
for(int i = 1; i <= n; i++)
for(int j = 1; j <= m; j++)
fen[i][j]=0;
}
void upd(int _x, int _y, int v){
_x++, _y++;
for(int x = _x; x<mxN; x+=x&-x)
for(int y = _y; y < mxN; y+=y&-y)
fen[x][y]+=v;
}
int sum(int _x, int _y){
int s = 0; _x++, _y++;
for(int x = _x; x>0; x-=x&-x)
for(int y = _y; y>0; y-=y&-y)
s+=fen[x][y];
return s;
}
int sum(int x1, int y1, int x2, int y2){
return sum(x2,y2)-sum(x1-1,y2)-sum(x2,y1-1)+sum(x1-1,y1-1);
}
} fen2d;
ll count_rectangles(vector<vi> a) {
n = sz(a); m = sz(a[0]); ll ans = 0;
for(int i = 0; i < n; i++){
stack<int> S = stack<int>();
for(int j = m-1; j >= 0; j--){
while(sz(S) and a[i][S.top()]<a[i][j]) S.pop();
if(sz(S) and abs(S.top()-j)>1)
row[i][j].pb(S.top());
S.push(j);
}
S = stack<int>();
for(int j = 0; j < m; j++){
while(sz(S) and a[i][S.top()]<a[i][j]) S.pop();
if(sz(S) and abs(S.top()-j)>1)
if(a[i][S.top()]!=a[i][j])
row[i][S.top()].pb(j);
S.push(j);
}
}
for(int j = 0; j < m; j++){
stack<int> S = stack<int>();
for(int i = n-1; i >= 0; i--){
while(sz(S) and a[S.top()][j]<a[i][j]) S.pop();
if(sz(S) and abs(S.top()-i)>1)
col[i][j].pb(S.top());
S.push(i);
}
S = stack<int>();
for(int i = 0; i < n; i++){
while(sz(S) and a[S.top()][j]<a[i][j]) S.pop();
if(sz(S) and abs(S.top()-i)>1)
if(a[S.top()][j]!=a[i][j])
col[S.top()][j].pb(i);
S.push(i);
}
}
for(int i = 0; i < n; i++)
for(int j = 0; j < m; j++)
sort(all(row[i][j])), sort(all(col[i][j]));
fen2d.init(n,m);
for(int i = 1; i < n-1; i++){
for(int j = 0; j < m; j++)
for(auto u : col[i-1][j])
grid[u][j]=1, grid2[u].pb(j);
for(int k = 0; k < n; k++){
for(auto u : grid2[k]){
int y = u;
if(!y or !grid[k][y-1]){
while(y<m-1 and grid[k][y+1]) y++;
lines[u].pb({k,y});
}
}
}
for(auto [x,y] : lines[0]) fen2d.upd(x,y,1);
for(int j = 0; j < m; j++){
for(auto [x,y] : lines[j+1]) fen2d.upd(x,y,1);
for(auto k : row[i][j]){
int R = i+1;
if(i>1 and binary_search(all(row[i-1][j]),k)){
R = found[i-1][j].lower_bound({k,-1})->second;
}
else{
while(R<n and binary_search(all(row[R][j]),k)) R++;
}
found[i][j].insert({k,R});
int xd = fen2d.sum(i+1,j,R,mxN-2); ans+=xd;
}
for(auto u : col[i-1][j]) grid[u][j]=0;
}
for(int j = 0; j < m; j++){
for(auto [x,y] : lines[j])
fen2d.upd(x,y,-1);
lines[j].clear();
}
for(int j = 0; j < m; j++)
for(int k = 0; k < n; k++) grid2[k].clear();
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 8
Accepted
time: 43ms
memory: 300548kb
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: 35ms
memory: 300544kb
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: 47ms
memory: 301220kb
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: 39ms
memory: 299792kb
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: 61ms
memory: 299760kb
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 441
result:
wrong answer 3rd lines differ - expected: '268', found: '441'
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: 44ms
memory: 300576kb
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: 66ms
memory: 301112kb
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: 40ms
memory: 300760kb
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: 35ms
memory: 300816kb
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: 43ms
memory: 300596kb
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 1392
result:
wrong answer 3rd lines differ - expected: '688', found: '1392'
Subtask #6:
score: 0
Wrong Answer
Test #64:
score: 0
Wrong Answer
time: 55ms
memory: 300388kb
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 3
result:
wrong answer 3rd lines differ - expected: '2', found: '3'
Subtask #7:
score: 0
Skipped
Dependency #1:
0%