#include<bits/stdc++.h>
using namespace std;
#define N 200010
#define M 2000000020
#define pb push_back
typedef long long ll;
typedef pair<ll,ll> pll;
map<ll,ll>st;
map<ll,ll>lazy;
vector<pll>range;
vector<ll>tests;
ll sum[N];
void LAZY(ll i,ll l,ll r)
{
if(lazy.find(i)==lazy.end())
return;
ll val=lazy[i],nxt=(i<<1);
lazy.erase(i);
st[i]+=(r-l+1)*val;
if(l==r)
return;
lazy[nxt]+=val;
lazy[nxt+1]+=val;
return;
}
void update(ll i,ll l,ll r,ll L,ll R,ll val)
{
LAZY(i,l,r);
if(l>R || L>r)
return;
if(L<=l && r<=R)
{
lazy[i]+=val;
return;
}
ll nxt=(i<<1),mid=((l+r)>>1);
update(nxt,l,mid,L,R,val);
update(nxt+1,mid+1,r,L,R,val);
st[i]+=(min(r,R)-max(l,L)+1)*val;
return;
}
ll query(ll i,ll l,ll r,ll L,ll R)
{
LAZY(i,l,r);
if(l>R || L>r)
return 0LL;
if(L<=l && r<=R)
return st[i];
ll nxt=(i<<1),mid=((l+r)>>1);
return query(nxt,l,mid,L,R)+
query(nxt+1,mid+1,r,L,R);
}
int main()
{
ll n,k,x,i=0,l,t,r,pos,val,cur=0,s=0,ans=0;
cin >> n >> k >> x;
while(i<n)
{
cin >> l >> t >> r;
range.pb({l,1});
range.pb({r+1,-1});
range.pb({l+t,2});
range.pb({r+1,-2});
i++;
}
sort(range.begin(),range.end());
i=0;
n*=4;
range.pb({-1,0});
while(i<n)
{
pos=range[i].first;
while(range[i].first==pos)
{
val=range[i].second;
if(val==1)
cur++;
if(val==-1)
cur--;
if(val==2)
s++;
if(val==-2)
s--;
i++;
}
if(cur>=k)
{
r=range[i].first-1;
update(1,1,M,pos,r,s);
tests.pb(pos);
tests.pb(max(0LL,r-x+1));
}
}
for(auto l : tests)
{
ans=max(ans,query(1,1,M,l,l+x-1));
}
cout << ans << endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
632 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
5 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
3 ms |
604 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
600 KB |
Output is correct |
16 |
Correct |
3 ms |
632 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
5 ms |
600 KB |
Output is correct |
21 |
Execution timed out |
1047 ms |
112652 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |