This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <set>
using namespace std;
#define pii pair<int,int>
const int INF=1e9+7;
int find_sheet(int n,int l,int r,vector<int>& t,int x,int a){
if(l==r&&t[n]>=x)return l;
if(l>a)return 0;
int mid=(r+l)/2;
if(mid+1<a&&t[(n<<1)+1]>=x)return find_sheet((n<<1)+1,mid+1,r,t,x,a);
return find_sheet((n<<1),l,mid,t,x,a);
}
void pupd(int n,int l,int r,vector<int>& t,int a,int x){
if(l>a||r<a)return;
if(l==r&&l==a)t[n]=x;
else{
int mid=(r+l)/2;
pupd(n<<1,l,mid,t,a,x);
pupd((n<<1)+1,mid+1,r,t,a,x);
t[n]=max(t[n<<1],t[(n<<1)+1]);
}
}
set<int> dfs(int a,vector<vector<int>>& g,vector<int>& ans,vector<set<int>>& color){
set<int> cnt=color[a];
for(int x:g[a]){
set<int> cnt2=dfs(x,g,ans,color);
if(cnt2.size()>cnt.size())swap(cnt,cnt2);
for(int c:cnt2)cnt.insert(c);
}
ans[a]=cnt.size();
return cnt;
}
int main(){
int n,m,a,b,c,d;
cin>>n>>m;
vector<pair<pii,pii>> sheet(n+1);
sheet[0]={{0,0},{INF,INF}};
set<int> s;
vector<pair<pii,int>> ball(m);
for(int i=1;i<=n;i++){
cin>>a>>b>>c>>d;
sheet[i]={{a,b},{c,d}};
s.insert(b);
s.insert(d);
}
for(int i=0;i<m;i++){
cin>>a>>b>>c;
ball[i]={{a,b},c};
s.insert(b);
}
s.insert(0);
s.insert(INF);
unordered_map<int,int> mp;
mp.reserve(262144);
int cnt=0;
for(int x:s){
mp[x]=cnt;
cnt++;
}
vector<int> tr(4*cnt),active(cnt),ans(n+1);
vector<pair<pair<pii,pii>,int>> q;
vector<set<int>> color(n+1,set<int>());
vector<vector<int>> g(n+1,vector<int>());
//1 add sheet and search bigger sheet
//3 delete
//2 search first sheet of ith ball
for(int i=0;i<=n;i++){
q.push_back({{{sheet[i].first.first,sheet[i].first.second},{1,sheet[i].second.second}},i});
q.push_back({{{sheet[i].second.first,sheet[i].second.second},{3,sheet[i].first.second}},i});
}
for(int j=0;j<m;j++){
q.push_back({{ball[j].first,{2,ball[j].second}},j});
}
sort(q.begin(),q.end());
//cout<<cnt<<'\n';
for(int i=0;i<q.size();i++){
int t=q[i].first.second.first,sheet=q[i].second,y1=q[i].first.first.second,y2=q[i].first.second.second;
//cout<<q[i].first.first.first<<' '<<y1<<' '<<t<<'\n';
if(t==1){
if(i){
int l=find_sheet(1,0,cnt-1,tr,mp[y2],mp[y1]);
g[active[l]].push_back(sheet);
}
//cout<<mp[y1]<<' '<<mp[y2]<<' '<<y1<<' '<<y2<<'\n';
pupd(1,0,cnt-1,tr,mp[y1],mp[y2]);
active[mp[y1]]=sheet;
//
}if(t==3){
pupd(1,0,cnt-1,tr,mp[y2],0);
active[mp[y2]]=0;
}if(t==2){
int l=find_sheet(1,0,cnt-1,tr,mp[y1],mp[y1]);
color[active[l]].insert(y2);
}
}
/*for(int i=0;i<=n;i++){
cout<<i<<':';
for(int x:color[i])cout<<x<<' ';
cout<<endl;
}*/
dfs(0,g,ans,color);
for(int i=1;i<=n;i++)cout<<ans[i]<<'\n';
}
Compilation message (stderr)
plahte.cpp: In function 'int main()':
plahte.cpp:79:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<std::pair<int, int>, std::pair<int, int> >, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | for(int i=0;i<q.size();i++){
| ~^~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |