# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
730535 |
2023-04-26T05:25:51 Z |
damwuan |
Plahte (COCI17_plahte) |
C++17 |
|
457 ms |
102868 KB |
#include<bits/stdc++.h>
using namespace std;
#define task "PAINT"
#define pb push_back
#define fi first
#define se second
#define bit(n,i) (((n)>>(i))&(1))
#define all(x) x.begin(),x.end()
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn= 8e4+69;
const ll inf=1e18;
const ll mod=1e9+7;
const ll base=311;
const ll prime=241029947;
int n,m,k[maxn];
pii a1[maxn],a2[maxn],b[maxn];
namespace subnm
{
set<int> s[maxn];
inline bool inside(int i,int j) {return (b[j].fi>=a1[i].fi && b[j].fi<=a2[i].fi && b[j].se>=a1[i].se && b[j].se<=a2[i].se );}
void solve()
{
for (int i=1;i<=n;i++)
{
for (int j=1;j<=m;j++)
{
if (inside(i,j)) s[i].insert(k[j]);
}
cout << s[i].size()<<'\n';
}
}
}
namespace full
{
vector<int> xxx,yyy,in[maxn*3],out[maxn*3],qr[maxn*3],adj[maxn];
vector<pii> st[maxn*12];
set<int> L[maxn];
int ans[maxn];
void dfs(int u)
{
for (int v: adj[u])
{
dfs(v);
if (L[v].size()>L[u].size()) L[u].swap(L[v]);
for (int x:L[v])L[u].insert(x);
}
ans[u]=L[u].size();
}
void Update(int u,int v,pii val,int id=1,int l=1,int r=yyy.size())
{
if (u>r || v<l) return;
if (u<=l && r<=v)
{
st[id].pb(val);
return;
}
int mid=l+r>>1;
Update(u,v,val,id*2,l,mid);
Update(u,v,val,id*2+1,mid+1,r);
}
void Erase(int u,int v,int id=1,int l=1,int r=yyy.size())
{
if (u>r || v<l) return;
if (u<=l && r<=v)
{
st[id].pop_back();
return;
}
int mid=l+r>>1;
Erase(u,v,id*2,l,mid);
Erase(u,v,id*2+1,mid+1,r);
}
pii Get(int u,int id=1,int l=1,int r=yyy.size())
{
if (l==r)
{
if (!st[id].empty())
{
return st[id].back();
}
return {0,0};
}
int mid=(l+r)/2;
pii x={0,0};
if (u<=mid) x=Get(u,id*2,l,mid);
else x=Get(u,id*2+1,mid+1,r);
if (!st[id].empty() && st[id].back().se>x.se)
{
return st[id].back();
}
return x;
}
void solve()
{
for (int i=1;i<=n;i++)
{
xxx.pb(a1[i].fi);
xxx.pb(a2[i].fi);
yyy.pb(a1[i].se);
yyy.pb(a2[i].se);
}
for (int i=1;i<=n;i++)
{
xxx.pb(b[i].fi);
yyy.pb(b[i].se);
}
sort(all(xxx));
sort(all(yyy));
xxx.resize(unique(all(xxx))-xxx.begin());
yyy.resize(unique(all(yyy))-yyy.begin());
for (int i=1;i<=n;i++)
{
a1[i].fi=lower_bound(all(xxx),a1[i].fi)-xxx.begin()+1;
a2[i].fi=lower_bound(all(xxx),a2[i].fi)-xxx.begin()+1;
a1[i].se=lower_bound(all(yyy),a1[i].se)-yyy.begin()+1;
a2[i].se=lower_bound(all(yyy),a2[i].se)-yyy.begin()+1;
//cout <<a1[i].fi<<' '<<a1[i].se<<' '<<a2[i].fi<<' '<< a2[i].se<<'\n';
in[a1[i].fi].pb(i);
out[a2[i].fi].pb(i);
}
for (int i=1;i<=m;i++)
{
b[i].fi=lower_bound(all(xxx),b[i].fi)-xxx.begin()+1;
b[i].se=lower_bound(all(yyy),b[i].se)-yyy.begin()+1;
qr[b[i].fi].pb(i);
}
for (int i=1;i<=xxx.size();i++)
{
//cout << i<<" bb \n";
for (int u: in[i])
{
int par=Get(a1[u].se).fi;
adj[par].pb(u);
//cout << u<<" <- "<<par<<'\n';
Update(a1[u].se,a2[u].se,{u,i});
//return;
}
for (int u: qr[i])
{
int x=Get(b[u].se).fi;
//cout <<"wtf "<< u<< " "<<x<<"\n";
L[x].insert(k[u]);
}
//cout << i<<" ba \n";
for (int u: out[i])
{
Erase(a1[u].se,a2[u].se);
}
}
// return;
// for (int i=1;i<=n;i++)
// {
// for (int v: adj[i]) cout << v<<' ';
// cout << '\n';
// }
dfs(0);
for (int i=1;i<=n;i++)
{
cout << ans[i]<<'\n';
}
}
}
void sol()
{
cin >> n>> m;
for (int i=1;i<=n;i++)
{
cin >>a1[i].fi>> a1[i].se>>a2[i].fi>> a2[i].se;
}
for (int i=1;i<=m;i++)
{
cin >> b[i].fi>> b[i].se>> k[i];
}
full::solve();
return;
if (n*m <= 1e6)
{
subnm::solve();
return;
}
}
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
// freopen(task".INP","r",stdin);
// freopen(task".out","w",stdout);
int t=1;//cin >> t;
for (int _=1;_<=t;_++)
{
//cout << "Case #"<<_<<":\n";
sol();
}
}
/*
12345
6 2
1 2 2
1 3 1
2 4 3
2 5 4
6 5 2
3 5
*/
Compilation message
plahte.cpp: In function 'void full::Update(long long int, long long int, pii, long long int, long long int, long long int)':
plahte.cpp:63:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
63 | int mid=l+r>>1;
| ~^~
plahte.cpp: In function 'void full::Erase(long long int, long long int, long long int, long long int, long long int)':
plahte.cpp:75:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
75 | int mid=l+r>>1;
| ~^~
plahte.cpp: In function 'void full::solve()':
plahte.cpp:134:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
134 | for (int i=1;i<=xxx.size();i++)
| ~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
60208 KB |
Output is correct |
2 |
Correct |
125 ms |
60608 KB |
Output is correct |
3 |
Correct |
26 ms |
49236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
157 ms |
66496 KB |
Output is correct |
2 |
Correct |
162 ms |
64048 KB |
Output is correct |
3 |
Incorrect |
25 ms |
49236 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
81984 KB |
Output is correct |
2 |
Correct |
251 ms |
72072 KB |
Output is correct |
3 |
Correct |
25 ms |
49220 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
457 ms |
102868 KB |
Output is correct |
2 |
Correct |
435 ms |
86288 KB |
Output is correct |
3 |
Correct |
25 ms |
49236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
442 ms |
97480 KB |
Output is correct |
2 |
Correct |
401 ms |
84592 KB |
Output is correct |
3 |
Incorrect |
25 ms |
49268 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |