Submission #126767

# Submission time Handle Problem Language Result Execution time Memory
126767 2019-07-08T11:37:11 Z TadijaSebez Examination (JOI19_examination) C++11
100 / 100
634 ms 25472 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int N=100050;
struct BIT2D
{
	vector<int> all[N],sum[N];
	BIT2D(){}
	void Ins(int x, int y){ for(int i=x;i;i-=i&-i) if(all[i].empty() || all[i].back()!=y) all[i].pb(y);}
	void Build(){ for(int i=1;i<N;i++) sum[i].resize(all[i].size());}
	int Pos(int x, int y){ return lower_bound(all[x].begin(),all[x].end(),y)-all[x].begin()+1;}
	void Set(int x, int y){ for(int i=x;i;i-=i&-i) for(int j=Pos(i,y);j;j-=j&-j) sum[i][j-1]++;}
	int Get(int x, int y){ int ans=0;for(int i=x;i<N;i+=i&-i) for(int j=Pos(i,y);j<=all[i].size();j+=j&-j) ans+=sum[i][j-1];return ans;}
} ST;
int qid[N],id[N],s[N],t[N],a[N],b[N],c[N],ans[N];
vector<int> cp;
int Pos(int x){ return lower_bound(cp.begin(),cp.end(),x)-cp.begin()+1;}
int main()
{
	int n,q;
	scanf("%i %i",&n,&q);
	for(int i=1;i<=n;i++) scanf("%i %i",&s[i],&t[i]),id[i]=i,cp.pb(s[i]);
	sort(cp.begin(),cp.end());cp.resize(unique(cp.begin(),cp.end())-cp.begin());
	sort(id+1,id+1+n,[&](int i, int j){ return t[i]<t[j];});
	for(int i=1;i<=n;i++) ST.Ins(Pos(s[id[i]]),t[id[i]]);ST.Build();
	sort(id+1,id+1+n,[&](int i, int j){ return s[i]+t[i]>s[j]+t[j];});
	for(int i=1;i<=q;i++) scanf("%i %i %i",&a[i],&b[i],&c[i]),qid[i]=i;
	sort(qid+1,qid+1+q,[&](int i, int j){ return c[i]>c[j];});
	for(int i=1,j=1;i<=q;i++)
	{
		for(;j<=n && s[id[j]]+t[id[j]]>=c[qid[i]];j++) ST.Set(Pos(s[id[j]]),t[id[j]]);
        ans[qid[i]]=ST.Get(Pos(a[qid[i]]),b[qid[i]]);
	}
	for(int i=1;i<=q;i++) printf("%i\n",ans[i]);
	return 0;
}

Compilation message

examination.cpp: In member function 'int BIT2D::Get(int, int)':
examination.cpp:13:80: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  int Get(int x, int y){ int ans=0;for(int i=x;i<N;i+=i&-i) for(int j=Pos(i,y);j<=all[i].size();j+=j&-j) ans+=sum[i][j-1];return ans;}
                                                                               ~^~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:25:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
  for(int i=1;i<=n;i++) ST.Ins(Pos(s[id[i]]),t[id[i]]);ST.Build();
  ^~~
examination.cpp:25:55: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  for(int i=1;i<=n;i++) ST.Ins(Pos(s[id[i]]),t[id[i]]);ST.Build();
                                                       ^~
examination.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%i %i",&n,&q);
  ~~~~~^~~~~~~~~~~~~~~
examination.cpp:22:58: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=n;i++) scanf("%i %i",&s[i],&t[i]),id[i]=i,cp.pb(s[i]);
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~
examination.cpp:27:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i=1;i<=q;i++) scanf("%i %i %i",&a[i],&b[i],&c[i]),qid[i]=i;
                        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 7 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 15 ms 5628 KB Output is correct
8 Correct 15 ms 5624 KB Output is correct
9 Correct 34 ms 5624 KB Output is correct
10 Correct 12 ms 5496 KB Output is correct
11 Correct 11 ms 5368 KB Output is correct
12 Correct 9 ms 5240 KB Output is correct
13 Correct 14 ms 5624 KB Output is correct
14 Correct 14 ms 5496 KB Output is correct
15 Correct 14 ms 5624 KB Output is correct
16 Correct 13 ms 5240 KB Output is correct
17 Correct 11 ms 5496 KB Output is correct
18 Correct 8 ms 5240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 20856 KB Output is correct
2 Correct 471 ms 20928 KB Output is correct
3 Correct 455 ms 20972 KB Output is correct
4 Correct 223 ms 15432 KB Output is correct
5 Correct 160 ms 12400 KB Output is correct
6 Correct 107 ms 10212 KB Output is correct
7 Correct 451 ms 20836 KB Output is correct
8 Correct 411 ms 20848 KB Output is correct
9 Correct 394 ms 20912 KB Output is correct
10 Correct 111 ms 11244 KB Output is correct
11 Correct 178 ms 14704 KB Output is correct
12 Correct 67 ms 9968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 455 ms 20856 KB Output is correct
2 Correct 471 ms 20928 KB Output is correct
3 Correct 455 ms 20972 KB Output is correct
4 Correct 223 ms 15432 KB Output is correct
5 Correct 160 ms 12400 KB Output is correct
6 Correct 107 ms 10212 KB Output is correct
7 Correct 451 ms 20836 KB Output is correct
8 Correct 411 ms 20848 KB Output is correct
9 Correct 394 ms 20912 KB Output is correct
10 Correct 111 ms 11244 KB Output is correct
11 Correct 178 ms 14704 KB Output is correct
12 Correct 67 ms 9968 KB Output is correct
13 Correct 510 ms 21484 KB Output is correct
14 Correct 511 ms 21460 KB Output is correct
15 Correct 453 ms 21084 KB Output is correct
16 Correct 253 ms 15724 KB Output is correct
17 Correct 186 ms 13040 KB Output is correct
18 Correct 100 ms 10224 KB Output is correct
19 Correct 500 ms 21448 KB Output is correct
20 Correct 492 ms 21388 KB Output is correct
21 Correct 477 ms 21488 KB Output is correct
22 Correct 111 ms 11120 KB Output is correct
23 Correct 176 ms 14564 KB Output is correct
24 Correct 67 ms 9840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 4984 KB Output is correct
3 Correct 6 ms 4984 KB Output is correct
4 Correct 7 ms 4984 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 4984 KB Output is correct
7 Correct 15 ms 5628 KB Output is correct
8 Correct 15 ms 5624 KB Output is correct
9 Correct 34 ms 5624 KB Output is correct
10 Correct 12 ms 5496 KB Output is correct
11 Correct 11 ms 5368 KB Output is correct
12 Correct 9 ms 5240 KB Output is correct
13 Correct 14 ms 5624 KB Output is correct
14 Correct 14 ms 5496 KB Output is correct
15 Correct 14 ms 5624 KB Output is correct
16 Correct 13 ms 5240 KB Output is correct
17 Correct 11 ms 5496 KB Output is correct
18 Correct 8 ms 5240 KB Output is correct
19 Correct 455 ms 20856 KB Output is correct
20 Correct 471 ms 20928 KB Output is correct
21 Correct 455 ms 20972 KB Output is correct
22 Correct 223 ms 15432 KB Output is correct
23 Correct 160 ms 12400 KB Output is correct
24 Correct 107 ms 10212 KB Output is correct
25 Correct 451 ms 20836 KB Output is correct
26 Correct 411 ms 20848 KB Output is correct
27 Correct 394 ms 20912 KB Output is correct
28 Correct 111 ms 11244 KB Output is correct
29 Correct 178 ms 14704 KB Output is correct
30 Correct 67 ms 9968 KB Output is correct
31 Correct 510 ms 21484 KB Output is correct
32 Correct 511 ms 21460 KB Output is correct
33 Correct 453 ms 21084 KB Output is correct
34 Correct 253 ms 15724 KB Output is correct
35 Correct 186 ms 13040 KB Output is correct
36 Correct 100 ms 10224 KB Output is correct
37 Correct 500 ms 21448 KB Output is correct
38 Correct 492 ms 21388 KB Output is correct
39 Correct 477 ms 21488 KB Output is correct
40 Correct 111 ms 11120 KB Output is correct
41 Correct 176 ms 14564 KB Output is correct
42 Correct 67 ms 9840 KB Output is correct
43 Correct 556 ms 25472 KB Output is correct
44 Correct 634 ms 25352 KB Output is correct
45 Correct 563 ms 25176 KB Output is correct
46 Correct 336 ms 19352 KB Output is correct
47 Correct 200 ms 14200 KB Output is correct
48 Correct 101 ms 10092 KB Output is correct
49 Correct 519 ms 25076 KB Output is correct
50 Correct 528 ms 25200 KB Output is correct
51 Correct 503 ms 25072 KB Output is correct
52 Correct 149 ms 13164 KB Output is correct
53 Correct 199 ms 17676 KB Output is correct