Submission #287279

# Submission time Handle Problem Language Result Execution time Memory
287279 2020-08-31T14:53:04 Z Blagojce Examination (JOI19_examination) C++11
2 / 100
1578 ms 160568 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 = 1000;
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, totb+1){
			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*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 17 ms 996 KB Output is correct
8 Correct 15 ms 996 KB Output is correct
9 Correct 15 ms 996 KB Output is correct
10 Correct 22 ms 996 KB Output is correct
11 Correct 14 ms 996 KB Output is correct
12 Correct 13 ms 996 KB Output is correct
13 Correct 16 ms 996 KB Output is correct
14 Correct 16 ms 996 KB Output is correct
15 Correct 16 ms 996 KB Output is correct
16 Correct 13 ms 868 KB Output is correct
17 Correct 14 ms 996 KB Output is correct
18 Correct 12 ms 740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1578 ms 160568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1578 ms 160568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 17 ms 996 KB Output is correct
8 Correct 15 ms 996 KB Output is correct
9 Correct 15 ms 996 KB Output is correct
10 Correct 22 ms 996 KB Output is correct
11 Correct 14 ms 996 KB Output is correct
12 Correct 13 ms 996 KB Output is correct
13 Correct 16 ms 996 KB Output is correct
14 Correct 16 ms 996 KB Output is correct
15 Correct 16 ms 996 KB Output is correct
16 Correct 13 ms 868 KB Output is correct
17 Correct 14 ms 996 KB Output is correct
18 Correct 12 ms 740 KB Output is correct
19 Incorrect 1578 ms 160568 KB Output isn't correct
20 Halted 0 ms 0 KB -