Submission #654115

#TimeUsernameProblemLanguageResultExecution timeMemory
654115jiahngRectangles (IOI19_rect)C++14
37 / 100
5024 ms130564 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> pi; typedef vector <int> vi; typedef vector <pi> vpi; typedef pair<pi, ll> pii; typedef pair <pi,pi> pipi; typedef set <ll> si; typedef long double ld; #define f first #define s second #define mp make_pair #define FOR(i,s,e) for(int i=s;i<=int(e);++i) #define DEC(i,s,e) for(int i=s;i>=int(e);--i) #define pb push_back #define all(x) (x).begin(), (x).end() #define lbd(x, y) lower_bound(all(x), y) #define ubd(x, y) upper_bound(all(x), y) #define aFOR(i,x) for (auto i: x) #define mem(x,i) memset(x,i,sizeof x) #define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define maxn 2501 #define INF (ll)1e9 #define MOD 1000000007 typedef pair <vi, int> pvi; typedef pair <int,pi> ipi; typedef vector <pii> vpii; int N,M; set <pi> hpairs[maxn], vpairs[maxn]; long long count_rectangles(std::vector<std::vector<int> > a) { N = a.size(); M = a[0].size(); FOR(i,0,N-1){ stack <pi> st; FOR(j,0,M-1){ while (!st.empty() && st.top().f < a[i][j]) st.pop(); if (!st.empty() && j - st.top().s + 1 >= 3) hpairs[i].insert(pi(st.top().s+1, j-1)); st.push(pi(a[i][j], j)); } while (!st.empty()) st.pop(); DEC(j,M-1,0){ while (!st.empty() && st.top().f < a[i][j]) st.pop(); if (!st.empty() && st.top().s - j + 1 >= 3) hpairs[i].insert(pi(j+1, st.top().s-1)); st.push(pi(a[i][j], j)); } } FOR(j,0,M-1){ stack <pi> st; FOR(i,0,N-1){ while (!st.empty() && st.top().f < a[i][j]) st.pop(); if (!st.empty() && i - st.top().s + 1 >= 3) vpairs[j].insert(pi(st.top().s+1, i-1)); st.push(pi(a[i][j], i)); } while (!st.empty()) st.pop(); DEC(i,N-1,0){ while (!st.empty() && st.top().f < a[i][j]) st.pop(); if (!st.empty() && st.top().s - i + 1 >= 3) vpairs[j].insert(pi(i+1, st.top().s-1)); st.push(pi(a[i][j], i)); } } /* cout << "HPAIRS: \n"; FOR(i,0,N-1){ cout << "ROW " << i << '\n'; aFOR(j, hpairs[i]) cout << j.f << ' ' << j.s << '\n'; } cout << "VPAIRS: \n"; FOR(i,0,M-1){ cout << "COL " << i << '\n'; aFOR(j, vpairs[i]) cout << j.f << ' ' << j.s << '\n'; } */ vector <pipi> hrects, vrects; FOR(i,0,N-1){ aFOR(j, hpairs[i]){ int a = i, b = j.f, c = N - 1, d = j.s; FOR(k,i+1,N-1){ if (hpairs[k].count(j)){ hpairs[k].erase(j); }else{ c = k - 1; break; } } hrects.pb(pipi(pi(a,b), pi(c,d))); } } FOR(i,0,M-1){ aFOR(j, vpairs[i]){ int a = j.f, b = i, c = j.s, d = M - 1; FOR(k,i+1,M-1){ if (vpairs[k].count(j)){ vpairs[k].erase(j); }else{ d = k - 1; break; } } vrects.pb(pipi(pi(a,b), pi(c,d))); } } /* cout << "HRECTS: \n"; aFOR(i, hrects) cout << i.f.f << ' ' << i.f.s << ' ' << i.s.f << ' ' << i.s.s << '\n'; cout << "VRECTS: \n"; aFOR(i, vrects) cout << i.f.f << ' ' << i.f.s << ' ' << i.s.f << ' ' << i.s.s << '\n'; */ int ans = 0; aFOR(i, hrects) aFOR(j, vrects){ if (!(i.f.f <= j.f.f && j.s.f <= i.s.f)) continue; if (!(j.f.s <= i.f.s && i.s.s <= j.s.s)) continue; //cout << i.f.f << ' ' << i.f.s << ' ' << i.s.f << ' ' << i.s.s << '\n'; //cout << j.f.f << ' ' << j.f.s << ' ' << j.s.f << ' ' << j.s.s << '\n' << '\n'; ans++; } 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...