Submission #824709

#TimeUsernameProblemLanguageResultExecution timeMemory
824709tomrukRectangles (IOI19_rect)C++17
50 / 100
1534 ms1048576 KiB
#include "rect.h" #include <bits/stdc++.h> #define N 2505 using namespace std; struct BIT2D{ vector<vector<int>> bit; int n; BIT2D(){ n = N; bit.assign(N,vector<int>(N,0)); } void upd(int x,int y,int val){ for(;x < n;x += x & -x){ for(;y < n;y += y & -y){ bit[x][y] += val; } } } int get(int x,int y){ int ret = 0; for(;x > 0;x -= x & -x){ for(;y > 0;y -= y & -y){ ret += bit[x][y]; } } return ret; } }; map<int,int> dwn[N][N]; map<int,int> rght[N][N]; long long count_rectangles(vector<vector<int>> a){ long long ans = 0; int n = a.size(); int m = a[0].size(); for(int i = m-1;i>=0;i--){ vector<int> nxt(n + 5,n); stack<int> st; st.push(n-1); for(int j = n-2;j>=0;j--){ while(st.size() && a[st.top()][i] <= a[j][i]) st.pop(); if(st.size()) nxt[j] = st.top(); st.push(j); if(a[j][i] <= a[j+1][i]) continue; for(int c = nxt[j + 1];c < n;c = nxt[c]){ rght[j][i][c] = 1 + rght[j][i+1][c]; if(a[j][i] <= a[c][i]) break; } } } int cnt = 0; BIT2D t; for(int i = n-1;i>0;i--){ vector<int> nxt(m + 5,m); stack<int> st; st.push(m-1); for(int j = m-2;j>=0;j--){ while(st.size() && a[i][st.top()] <= a[i][j]) st.pop(); if(st.size()) nxt[j] = st.top(); st.push(j); if(a[i][j] <= a[i][j+1]) continue; for(int c = nxt[j + 1];c < m;c = nxt[c]){ dwn[i][j][c] = 1 + dwn[i + 1][j][c]; for(int d = i + 1;d <= i + dwn[i][j][c];d++){ ans += (j + 1 + rght[i-1][j+1][d]) >= c; } if(a[i][j] <= a[i][c]) break; } } } assert(cnt <= n * m); return ans; }
#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...