# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
282265 |
2020-08-24T08:25:20 Z |
최은수(#5756) |
None (JOI15_walls) |
C++17 |
|
107 ms |
8568 KB |
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#define ep emplace
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const int inf=1e9+7;
const ll INF=1e18;
const int mx=200010;
struct fen
{
pi t[mx];
inline void upd(int x,pi p)
{
for(x=mx-3-x;x<mx;x+=x&-x)
t[x]=max(t[x],p);
return;
}
inline pi query(int x)
{
pi ret(-3,0);
for(x=mx-3-x;x>0;x^=x&-x)
ret=max(ret,t[x]);
return ret;
}
}fl,fr;
ll cans;
int ccnt;
inline void upd(pi x,pi y,int typ)
{
cans+=typ*abs(x.fi-y.fi);
if(x.se!=y.se)
ccnt+=typ;
return;
}
map<int,pi>mp;
inline void put(pair<pi,int>q)
{
int tm=q.fi.fi;
int pos=q.fi.se;
int typ=q.se;
auto it=mp.lower_bound(tm);
if(it!=mp.begin())
{
auto it2=it;
it2--;
if(it!=mp.end())
upd(it->se,it2->se,-1);
upd(pi(pos,typ),it2->se,1);
}
if(it!=mp.end())
upd(pi(pos,typ),it->se,1);
mp[tm]=pi(pos,typ);
return;
}
int a[mx],b[mx];
ll ans[mx];
vector<pair<pi,int> >mv[mx];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n,m;
cin>>n>>m;
for(int i=0;i<n;i++)
cin>>a[i]>>b[i],b[i]-=a[i];
vector<int>v(n);
for(int i=0;i<n;i++)
v[i]=i;
sort(all(v),[&](const int&x,const int&y){return b[x]<b[y];});
int pp=0;
for(int i=0;i<n;i++)
fl.upd(i,pi(-1,0)),fr.upd(i,pi(-2,0));
for(int i=0;i<m;i++)
{
int p;
cin>>p;
int s=-1,e=n-1;
while(s<e)
{
int md=s+(e-s+1)/2;
pi p1=fl.query(md);
pi p2=fr.query(md);
p2.se-=b[v[md]];
int cp=max(p1,p2).se;
if(p<cp||p>cp+b[v[md]])
s=md;
else
e=md-1;
}
if(s>=0)
{
if(pp<p)
fr.upd(s,pi(i,p));
else
fl.upd(s,pi(i,p));
mv[s].eb(pi(i,p),pp<p?1:0);
pp=p;
}
}
mp[-1]=pi(0,0);
for(int i=n;i-->0;)
{
for(auto&t:mv[i])
put(t);
cout<<cans<<' '<<ccnt<<endl;
ans[v[i]]=cans-(ll)b[v[i]]*ccnt;
}
for(int i=0;i<n;i++)
cout<<ans[i]<<'\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
5952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
107 ms |
8568 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
8 ms |
5952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |