# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
417441 |
2021-06-03T17:45:14 Z |
doowey |
Autobahn (COI21_autobahn) |
C++14 |
|
1000 ms |
61520 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = (int)1e6 + 10;
int T[N];
int L[N];
int R[N];
vector<int> imp;
vector<pii> segm;
int cnt[N];
int ban[N];
struct Node{
ll val;
int cnt;
ll lzy;
};
Node TR[N * 4 + 512];
void push(int node, int cl, int cr){
TR[node].val += TR[node].lzy * 1ll * (segm[cr].se - segm[cl].fi + 1);
TR[node].cnt += TR[node].lzy;
if(cl != cr){
TR[node * 2].lzy += TR[node].lzy;
TR[node * 2 + 1].lzy += TR[node].lzy;
}
TR[node].lzy = 0;
}
void upd(int node, int cl, int cr, int tl, int tr, int v){
push(node, cl, cr);
if(cr < tl || cl > tr) return;
if(cl >= tl && cr <= tr){
TR[node].lzy = v;
push(node, cl, cr);
return;
}
int mid =(cl + cr) / 2;
upd(node * 2, cl, mid, tl, tr, v);
upd(node * 2 + 1, mid + 1, cr, tl, tr, v);
TR[node].val = TR[node * 2].val + TR[node * 2 + 1].val;
}
int getcnt(int node, int cl, int cr, int iq){
push(node, cl, cr);
if(cl == cr)
return TR[node].cnt;
int mid = (cl + cr) / 2;
if(mid >= iq)
return getcnt(node * 2, cl, mid, iq);
else
return getcnt(node * 2 + 1, mid + 1, cr, iq);
}
ll get(int node, int cl, int cr, int tl, int tr){
push(node, cl, cr);
if(cr < tl || cl > tr) return 0ll;
if(cl >= tl && cr <= tr){
return TR[node].val;
}
int mid = (cl + cr) / 2;
return get(node * 2, cl, mid, tl, tr) + get(node * 2 + 1, mid + 1, cr, tl, tr);
}
int main(){
fastIO;
int n, k, x;
cin >> n >> k >> x;
for(int i = 1; i <= n; i ++ ){
cin >> L[i] >> T[i] >> R[i];
imp.push_back(L[i]);
imp.push_back(R[i]);
if(L[i] + T[i] <= R[i]){
imp.push_back(L[i] + T[i]);
}
}
sort(imp.begin(), imp.end());
imp.resize(unique(imp.begin(), imp.end()) - imp.begin());
for(int i = 0 ; i < imp.size(); i ++ ){
segm.push_back(mp(imp[i], imp[i]));
if(i + 1 < imp.size()){
if(imp[i] + 1 <= imp[i + 1] - 1)
segm.push_back(mp(imp[i] + 1, imp[i + 1] - 1));
}
}
int m = segm.size();
int lf, rf;
for(int i = 1; i <= n; i ++ ){
lf = lower_bound(segm.begin(), segm.end(), mp(L[i], L[i])) - segm.begin();
rf = lower_bound(segm.begin(), segm.end(), mp(R[i], R[i])) - segm.begin();
cnt[lf] ++ ;
cnt[rf + 1] -- ;
if(L[i] + T[i] <= R[i]){
lf = lower_bound(segm.begin(), segm.end(), mp(L[i] + T[i], L[i] + T[i])) - segm.begin();
ban[lf] ++ ;
ban[rf + 1] -- ;
}
}
ll res = 0;
for(int i = 1; i < m ; i ++ ){
cnt[i] += cnt[i - 1];
ban[i] += ban[i - 1];
}
for(int i = 0 ; i < m ; i ++ ){
if(cnt[i] < k){
ban[i] = 0;
}
}
for(int i = 0 ; i < m ; i ++ ){
upd(1, 0, m - 1, i, i, ban[i]);
}
int iqx;
int nex;
int las;
ll val;
int cc;
for(int i = 0 ; i < m ; i ++ ){
las = lower_bound(segm.begin(), segm.end(), mp(segm[i].fi + x, -1)) - segm.begin();
if(las == m) las ++ ;
las -- ;
val = get(1, 0, m - 1, i, las - 1);
if(las < m){
cc = getcnt(1, 0, m - 1, las);
val += max(0,((segm[i].fi + x - 1) - segm[las].fi + 1)) * 1ll * cc;
}
res = max(res, val);
las = lower_bound(segm.begin(), segm.end(), mp(segm[i].se - x + 1, -1)) - segm.begin();
val = get(1, 0, m - 1, las, i);
if(las > 0){
cc = getcnt(1, 0, m - 1, las - 1);
val += max(0,(segm[las - 1].se - (segm[i].se - x + 1) + 1)) * 1ll * cc;
}
res = max(res, val);
}
cout << res << "\n";
return 0;
}
Compilation message
autobahn.cpp: In function 'int main()':
autobahn.cpp:94:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
94 | for(int i = 0 ; i < imp.size(); i ++ ){
| ~~^~~~~~~~~~~~
autobahn.cpp:96:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | if(i + 1 < imp.size()){
| ~~~~~~^~~~~~~~~~~~
autobahn.cpp:127:9: warning: unused variable 'iqx' [-Wunused-variable]
127 | int iqx;
| ^~~
autobahn.cpp:128:9: warning: unused variable 'nex' [-Wunused-variable]
128 | int nex;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
2 ms |
460 KB |
Output is correct |
13 |
Correct |
2 ms |
460 KB |
Output is correct |
14 |
Correct |
2 ms |
332 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
2 ms |
332 KB |
Output is correct |
17 |
Correct |
2 ms |
456 KB |
Output is correct |
18 |
Correct |
2 ms |
460 KB |
Output is correct |
19 |
Correct |
2 ms |
460 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Execution timed out |
1097 ms |
61520 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |