Submission #126854

# Submission time Handle Problem Language Result Execution time Memory
126854 2019-07-08T14:17:07 Z mahmoudbadawy Examination (JOI19_examination) C++17
22 / 100
3000 ms 151660 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops") 
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define F first
#define S second

using namespace std;
using namespace __gnu_pbds;

typedef tree<
pair<int,int>,
null_type,
less<pair<int,int> >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;

const int N=1e5+5;

ordered_set btree[4*N];
pair<int,int> arr[N];
pair<pair<int,int>, pair<int,int> > qs[N];
vector<int> cmp;
int ans[N];
int n,q;

int get(int x)
{
	return lower_bound(cmp.begin(),cmp.end(),x)-cmp.begin();
}

void add(int ind,int sm,int x,int node=1,int l=0,int r=cmp.size()-1)
{
	if(r<ind||l>ind) return;
	btree[node].insert({sm,x});
	if(l==r)
		return;
	int mid=(l+r)/2;
	add(ind,sm,x,node*2,l,mid);
	add(ind,sm,x,node*2+1,mid+1,r);
}

void rem(int ind,int sm,int x,int node=1,int l=0,int r=cmp.size()-1)
{
	if(r<ind||l>ind) return;
	btree[node].erase({sm,x});
	if(l==r)
		return;
	int mid=(l+r)/2;
	rem(ind,sm,x,node*2,l,mid);
	rem(ind,sm,x,node*2+1,mid+1,r);
}

int query(int ql,int qr,int val,int node=1,int l=0,int r=cmp.size()-1)
{
	if(r<ql||qr<l) return 0;
	if(ql<=l&&r<=qr)
	{
		return btree[node].size()-btree[node].order_of_key({val,-1});
	}
	int mid=(l+r)/2;
	return query(ql,qr,val,node*2,l,mid)+query(ql,qr,val,node*2+1,mid+1,r);
}

int main()
{
	scanf("%d %d",&n,&q);
	for(int i=0;i<n;i++)
	{
		scanf("%d %d",&arr[i].F,&arr[i].S);
		cmp.push_back(arr[i].S);
	}
	for(int i=0;i<q;i++)
	{
		scanf("%d %d %d",&qs[i].F.F,&qs[i].F.S,&qs[i].S.F);
		qs[i].S.S=i;
		cmp.push_back(qs[i].F.S);
	}
	sort(cmp.begin(),cmp.end());
	cmp.erase(unique(cmp.begin(),cmp.end()),cmp.end());
	sort(arr,arr+n);
	sort(qs,qs+q);
	for(int i=0;i<n;i++)
	{
		add(get(arr[i].S),arr[i].F+arr[i].S,i);
	}
	int curs=0;
	for(int i=0;i<q;i++)
	{
		while(arr[curs].F<qs[i].F.F)
		{
			rem(get(arr[curs].S),arr[curs].F+arr[curs].S,curs);
			curs++;
		}
		/*cout << "ON " << qs[i].F.F << " " << curs << endl;
		for(int i=0;i<btree[1].size();i++)
		{
			auto x=*btree[1].find_by_order(i);
			cout << x.F << " " << x.S << endl;
		}*/
		ans[qs[i].S.S]=query(get(qs[i].F.S),cmp.size()-1,qs[i].S.F);
	}
	for(int i=0;i<q;i++)
		printf("%d\n",ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:69:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
examination.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&arr[i].F,&arr[i].S);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:77:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&qs[i].F.F,&qs[i].F.S,&qs[i].S.F);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 54 ms 37880 KB Output is correct
2 Correct 51 ms 37884 KB Output is correct
3 Correct 50 ms 37920 KB Output is correct
4 Correct 50 ms 37880 KB Output is correct
5 Correct 118 ms 37880 KB Output is correct
6 Correct 117 ms 37948 KB Output is correct
7 Correct 228 ms 40568 KB Output is correct
8 Correct 232 ms 40568 KB Output is correct
9 Correct 228 ms 40568 KB Output is correct
10 Correct 115 ms 39040 KB Output is correct
11 Correct 70 ms 40696 KB Output is correct
12 Correct 58 ms 38904 KB Output is correct
13 Correct 234 ms 40668 KB Output is correct
14 Correct 235 ms 40568 KB Output is correct
15 Correct 228 ms 40548 KB Output is correct
16 Correct 74 ms 40568 KB Output is correct
17 Correct 56 ms 38364 KB Output is correct
18 Correct 59 ms 38620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2771 ms 151540 KB Output is correct
2 Correct 2819 ms 151504 KB Output is correct
3 Correct 2750 ms 151628 KB Output is correct
4 Correct 470 ms 70448 KB Output is correct
5 Correct 1394 ms 151660 KB Output is correct
6 Correct 421 ms 70420 KB Output is correct
7 Correct 2296 ms 151552 KB Output is correct
8 Correct 2731 ms 148808 KB Output is correct
9 Correct 2232 ms 148780 KB Output is correct
10 Correct 891 ms 151500 KB Output is correct
11 Correct 367 ms 54468 KB Output is correct
12 Correct 439 ms 60428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2771 ms 151540 KB Output is correct
2 Correct 2819 ms 151504 KB Output is correct
3 Correct 2750 ms 151628 KB Output is correct
4 Correct 470 ms 70448 KB Output is correct
5 Correct 1394 ms 151660 KB Output is correct
6 Correct 421 ms 70420 KB Output is correct
7 Correct 2296 ms 151552 KB Output is correct
8 Correct 2731 ms 148808 KB Output is correct
9 Correct 2232 ms 148780 KB Output is correct
10 Correct 891 ms 151500 KB Output is correct
11 Correct 367 ms 54468 KB Output is correct
12 Correct 439 ms 60428 KB Output is correct
13 Correct 2935 ms 151580 KB Output is correct
14 Correct 2887 ms 151644 KB Output is correct
15 Correct 2716 ms 151584 KB Output is correct
16 Correct 548 ms 70624 KB Output is correct
17 Correct 1385 ms 151572 KB Output is correct
18 Correct 423 ms 70540 KB Output is correct
19 Execution timed out 3055 ms 150956 KB Time limit exceeded
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 54 ms 37880 KB Output is correct
2 Correct 51 ms 37884 KB Output is correct
3 Correct 50 ms 37920 KB Output is correct
4 Correct 50 ms 37880 KB Output is correct
5 Correct 118 ms 37880 KB Output is correct
6 Correct 117 ms 37948 KB Output is correct
7 Correct 228 ms 40568 KB Output is correct
8 Correct 232 ms 40568 KB Output is correct
9 Correct 228 ms 40568 KB Output is correct
10 Correct 115 ms 39040 KB Output is correct
11 Correct 70 ms 40696 KB Output is correct
12 Correct 58 ms 38904 KB Output is correct
13 Correct 234 ms 40668 KB Output is correct
14 Correct 235 ms 40568 KB Output is correct
15 Correct 228 ms 40548 KB Output is correct
16 Correct 74 ms 40568 KB Output is correct
17 Correct 56 ms 38364 KB Output is correct
18 Correct 59 ms 38620 KB Output is correct
19 Correct 2771 ms 151540 KB Output is correct
20 Correct 2819 ms 151504 KB Output is correct
21 Correct 2750 ms 151628 KB Output is correct
22 Correct 470 ms 70448 KB Output is correct
23 Correct 1394 ms 151660 KB Output is correct
24 Correct 421 ms 70420 KB Output is correct
25 Correct 2296 ms 151552 KB Output is correct
26 Correct 2731 ms 148808 KB Output is correct
27 Correct 2232 ms 148780 KB Output is correct
28 Correct 891 ms 151500 KB Output is correct
29 Correct 367 ms 54468 KB Output is correct
30 Correct 439 ms 60428 KB Output is correct
31 Correct 2935 ms 151580 KB Output is correct
32 Correct 2887 ms 151644 KB Output is correct
33 Correct 2716 ms 151584 KB Output is correct
34 Correct 548 ms 70624 KB Output is correct
35 Correct 1385 ms 151572 KB Output is correct
36 Correct 423 ms 70540 KB Output is correct
37 Execution timed out 3055 ms 150956 KB Time limit exceeded
38 Halted 0 ms 0 KB -