Submission #529402

# Submission time Handle Problem Language Result Execution time Memory
529402 2022-02-23T01:39:07 Z jiahng Autobahn (COI21_autobahn) C++14
50 / 100
1000 ms 524292 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define ll int
typedef pair<int,int> pi;
typedef vector <ll> vi;
typedef vector <pi> vpi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define MOD 1000000007
#define maxn 2000010
//~ #define getchar_unlocked _getchar_nolock

int N,K,X,l,r,t;

inline int readInt() {
    int x = 0;
    char ch = getchar_unlocked();
    while (ch < '0' || ch > '9') ch = getchar_unlocked();
    while (ch >= '0' && ch <= '9'){
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
    return x;
}

struct node{ // All adds before sets
	int s,e,v=0;
	bool init = 0;
	node *l=nullptr,*r;
	bool lazyset = 0;
	int lazy = 0;
	
	node (int ss,int ee){
		s = ss; e = ee;
	}
	void create(){
		if (s == e) return;
		if (!init){
			init = 1;
			l = new node(s,(s+e)/2); r = new node((s+e)/2+1,e);
		}
	}
	void prop(){
		if (s == e) return;
		create();
		if (lazy != 0){
			l->lazy += lazy; r->lazy += lazy;
			l->v += lazy * (l->e - l->s + 1); r->v += lazy * (r->e - r->s + 1);
		}
		if (lazyset){
			l->lazyset = r->lazyset = 1;
			l->v = r->v = 0;
		}
		lazy = lazyset = 0;
	}
		
	void upd(int a,int b,int c){
		prop();
		if (a > b) return;
		if (a <= s && e <= b){
			v += c * (e - s + 1); lazy += c;
		}else if (a > e || s > b) return;
		else{
			l->upd(a,b,c); r->upd(a,b,c);
			v = l->v + r->v;
		}
	}
	void set(int a,int b){
		prop();
		if (a > b) return;
		if (v == 0) return;
		if (a <= s && e <= b){
			lazyset = 1; v = 0;
		}else if (a > e || s > b) return;
		else{
			l->set(a,b); r->set(a,b);
			v = l->v + r->v;
		}
	}
	int qry(int a,int b){
		prop();
		if (a > b) return 0;
		if (v == 0) return 0;
		if (a <= s && e <= b) return v;
		else if (a > e || s > b) return 0;
		else{
			prop(); return l->qry(a,b) + r->qry(a,b);
		}
	}
}*root;

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int32_t main() {
    fast;
    N = readInt(); K = readInt(); X = readInt();
    //~ cin >> N >> K >> X;
    root = new node(1,1e9);
    unordered_map <int,int,custom_hash> mp; vi vect;
    vi v2;
    FOR(i,1,N){
		l = readInt(); t = readInt(); r = readInt();
		//~ cin >> l >> t >> r;
		if (l + t <= r){
			vect.pb(l+t);
			root->upd(l + t, r, 1);
		}
		mp[l]++; mp[r+1]--;
		v2.pb(l); v2.pb(r+1);
		vect.pb(l); vect.pb(r);
		vect.pb(l-X+1); vect.pb(r-X+1);
	}
	int cur = 0, pre = 1e9+1; // previous one < K
	
	
	
	sort(all(v2)); v2.erase(unique(all(v2)), v2.end());
	//~ root->set(1, v2[0]-1);
	aFOR(i,v2){
		if (cur < K && cur + mp[i] >= K){
			root->set(pre, i-1);
		}	
		cur += mp[i];
		//~ cout << "VAL: " << i.f << ' ' << cur << '\n';
		if (cur < K) pre = min(pre, i);
		else pre = 1e9+1;
	}
	if (cur < K) root->set(pre, 1e9);
	
	int ans = 0;
	aFOR(i,vect) if (i >= 1){
		//~ cout << i << ' ' << root->qry(i, i + X - 1) << '\n';;
		ans = max(ans, root->qry(i, min((int)1e9, i + X-1)));
	}
	cout << ans;
}

# 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 204 KB Output is correct
11 Correct 0 ms 204 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 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 488 KB Output is correct
20 Correct 3 ms 464 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 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 4 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 4 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 3 ms 460 KB Output is correct
17 Correct 4 ms 460 KB Output is correct
18 Correct 3 ms 460 KB Output is correct
19 Correct 3 ms 488 KB Output is correct
20 Correct 3 ms 464 KB Output is correct
21 Execution timed out 1016 ms 524292 KB Time limit exceeded
22 Halted 0 ms 0 KB -