제출 #906283

#제출 시각아이디문제언어결과실행 시간메모리
906283vjudge1Rectangles (IOI19_rect)C++17
컴파일 에러
0 ms0 KiB
#include "rect.h" #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for(int i = a; i < (b); ++i) #define all(x) begin(x), end(x) #define sz(x) (int)(x).size() #define F first #define S second #define pb push_back #define int short typedef pair<int, int> pii; typedef vector<int> vi; long long count_rectangles(std::vector<std::vector<int> > a) { int n = sz(a); int m = sz(a[0]); #define GET(a, item) lower_bound(all(a), pair<int, int>(item, -1)) auto has = [&](const vector<pair<int, int>>& a, int item) { auto ptr = lower_bound(all(a), pair<int, int>(item, -1)); return ptr != a.end() and ptr->first == item; }; vector<vector<vector<pair<int,int>>>> rowf(n,vector<vector<pair<int,int>>>(m)); rep(i,0,n){ vector<pii> stack; rep(j,0,m){ while(sz(stack) && stack.back().F < a[i][j]){ if(stack.back().S+1 <= j-1) { rowf[i][stack.back().S+1].emplace_back(j-1, -1); // cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl; } stack.pop_back(); } if(sz(stack) && stack.back().S+1 <= j-1) { // cout<<"push "<<(stack.back().S+1)<<" to "<<j-1<<endl; rowf[i][stack.back().S+1].emplace_back(j-1, -1); } while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back(); stack.pb({a[i][j],j}); } } vector<vector<vector<pair<int,int>>>> colf(n,vector<vector<pair<int,int>>>(m)); rep(j,0,m){ vector<pii> stack; rep(i,0,n){ while(sz(stack) && stack.back().F < a[i][j]){ if(stack.back().S+1<=i-1) colf[stack.back().S+1][j].emplace_back(i-1, -1); stack.pop_back(); } if(sz(stack) && stack.back().S+1<=i-1) colf[stack.back().S+1][j].emplace_back(i-1, -1); while(sz(stack) && stack.back().F == a[i][j]) stack.pop_back(); stack.pb({a[i][j],i}); } } rep(i,0,n)rep(j,0,m){ for(auto p : rowf[i][j]){ if(p.S == -1){ int k = i; while(k<n && has(rowf[k][j], p.F)) k++; rep(l,i,k) { GET(rowf[l][j], p.F)->second=k-1; } } } for(auto p : colf[i][j]){ if(p.S == -1){ int k = j; while(k<m && has(colf[i][k], p.F)) k++; rep(l,j,k) { GET(colf[i][l], p.F)->second=k-1; } } } } // rep(i,0,n){ // rep(j,0,m){ // cout<<i<<' '<<j<<" rows:"; // for(pii x : rowf[i][j]) cout<<' '<<x.F<<","<<x.S; // cout<<endl; // cout<<i<<' '<<j<<" cols:"; // for(pii x : colf[i][j]) cout<<' '<<x.F<<","<<x.S; // cout<<endl; // } // } long long ans = 0; rep(i,0,n){ rep(j,0,m){ for(pii l : colf[i][j])for(pii r : rowf[i][j]){ // [i, r.F], r.S tells how far we go on other // [j, l.F], l.S tells how far we go on other bool good = l.S>=r.F && r.S >= l.F; // cout<<i<<' '<<j<<" ("<<l.F<<','<<l.S<<") ("<<r.F<<','<<r.S<<") "<<good<<endl; ans += good; } } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

/usr/bin/ld: /tmp/ccGWI36d.o: in function `main':
grader.cpp:(.text.startup+0x6fa): undefined reference to `count_rectangles(std::vector<std::vector<int, std::allocator<int> >, std::allocator<std::vector<int, std::allocator<int> > > >)'
collect2: error: ld returned 1 exit status