Submission #287286

# Submission time Handle Problem Language Result Execution time Memory
287286 2020-08-31T14:56:28 Z Blagojce Examination (JOI19_examination) C++11
2 / 100
3000 ms 293316 KB
#include <bits/stdc++.h> 
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
 
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
 
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi  = 3.14159265359;
 
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 2e5;
 
const ll A = 911382323;
const ll B = 972663749;

int n, m;
int s[mxn], t[mxn];
int a[mxn], b[mxn], c[mxn];
int ans[mxn];
int arr[mxn];

int range1;
int range2;

void compress(){
	vector<pii> v;
	vector<pii> g;
	fr(i, 0, n){
		v.pb({s[i], i+1});
		g.pb({t[i], i+1});
	}
	fr(i, 0, m){
		v.pb({a[i],-i-1});
		g.pb({b[i],-i-1});
	}
	sort(all(v));
	sort(all(g));
	int nwv = 0;
	for(auto u : v){
		nwv ++;
		if(u.nd > 0) s[u.nd-1] = nwv; 
		if(u.nd < 0) a[-u.nd-1] = nwv;
		
	}
	range1 = nwv;
	nwv = 0;
	for(auto u : g){
		nwv ++;
		if(u.nd > 0) t[u.nd-1] = nwv;
		if(u.nd < 0) b[-u.nd-1] = nwv;
	}
	range2 = nwv;
}

const int bsz = 500;
int bit[500][mxn];
int cnt[mxn];
void update(int block, int k, int v){
	while(k < mxn){
		bit[block][k] += v;
		k += k&-k;
	}
}
int sum(int block, int k){
	int s = 0;
	while(k > 0){
		s += bit[block][k];
		k -= k&-k;
	}
	return s;
}

void solve(){
	cin >> n >> m;
	vector<int> v;
	fr(i, 0, n){
		cin >> s[i] >> t[i];
		v.pb(i);
	}
	sort(all(v), [](const int &i, const int &j){
		return s[i]+t[i] > s[j] + t[j];
	});
	int oldsum[n];
	fr(i, 0, n){
		oldsum[i] = s[v[i]] + t[v[i]];
	}
	
	
	vector<int> g;
	fr(i, 0, m){
		cin >> a[i] >> b[i] >> c[i];
		g.pb(i);
	}
	sort(all(g), [](const int &i, const int &j){
		return c[i] > c[j];
	});
	compress();
	
	
	int pos = 0;
	int totb = (range1+bsz-1)/bsz;
		
	for(auto u : g){
		while(pos < n && oldsum[pos] >= c[u]){
			arr[s[v[pos]]] = t[v[pos]];
			int bi = (s[v[pos]]-1)/bsz;
			update(bi, t[v[pos]], +1);
			++cnt[bi];
			++pos;
		}	
		int bi = (a[u]-1)/bsz;
		int p = a[u];
		while((p-1)/bsz == bi){
			if(arr[p] >= b[u]) ans[u] ++;
			++p;
		}
		fr(j, bi+1, 500){
			ans[u] += cnt[j]-sum(j, b[u]-1);
		}
	}
	fr(i, 0, m){
		cout<<ans[i]<<endl;
	}
}


int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tc = 1;
	//cin >> tc;
	while(tc--) solve();
}/*
10 1
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009*/

Compilation message

examination.cpp: In function 'void solve()':
examination.cpp:114:6: warning: unused variable 'totb' [-Wunused-variable]
  114 |  int totb = (range1+bsz-1)/bsz;
      |      ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 2 ms 1280 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 41 ms 2140 KB Output is correct
8 Correct 40 ms 2148 KB Output is correct
9 Correct 41 ms 2148 KB Output is correct
10 Correct 38 ms 2104 KB Output is correct
11 Correct 40 ms 2140 KB Output is correct
12 Correct 38 ms 2020 KB Output is correct
13 Correct 40 ms 2148 KB Output is correct
14 Correct 42 ms 2268 KB Output is correct
15 Correct 41 ms 2272 KB Output is correct
16 Correct 37 ms 1764 KB Output is correct
17 Correct 36 ms 2020 KB Output is correct
18 Correct 34 ms 1636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3018 ms 293316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3018 ms 293316 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1152 KB Output is correct
2 Correct 2 ms 1280 KB Output is correct
3 Correct 1 ms 1152 KB Output is correct
4 Correct 1 ms 1152 KB Output is correct
5 Correct 1 ms 1152 KB Output is correct
6 Correct 1 ms 1152 KB Output is correct
7 Correct 41 ms 2140 KB Output is correct
8 Correct 40 ms 2148 KB Output is correct
9 Correct 41 ms 2148 KB Output is correct
10 Correct 38 ms 2104 KB Output is correct
11 Correct 40 ms 2140 KB Output is correct
12 Correct 38 ms 2020 KB Output is correct
13 Correct 40 ms 2148 KB Output is correct
14 Correct 42 ms 2268 KB Output is correct
15 Correct 41 ms 2272 KB Output is correct
16 Correct 37 ms 1764 KB Output is correct
17 Correct 36 ms 2020 KB Output is correct
18 Correct 34 ms 1636 KB Output is correct
19 Execution timed out 3018 ms 293316 KB Time limit exceeded
20 Halted 0 ms 0 KB -