Submission #486167

# Submission time Handle Problem Language Result Execution time Memory
486167 2021-11-10T16:50:11 Z MilosMilutinovic Examination (JOI19_examination) C++17
43 / 100
569 ms 49160 KB
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=501000;
int n,q,s[N],t[N],x[N],y[N],z[N],q1,q2,ans[N];

struct st {
	int x,y,z,id;
}c1[N],c2[N];

struct fenwick {
	int n,c[N];
	void modify(int x,int y) {
		for (;x<N;x+=x&-x) c[x]+=y;
	}
	int query(int x) {
		int res=0;
		for (--x;x;x-=x&-x) res+=c[x];
		return res;
	}
};

int main() {
	VI v;
	scanf("%d%d",&n,&q);
	rep(i,1,n+1) scanf("%d%d",s+i,t+i),v.pb(s[i]),v.pb(t[i]),v.pb(s[i]+t[i]);
	rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),v.pb(x[i]),v.pb(y[i]),v.pb(z[i]);
	sort(all(v));
	v.erase(unique(all(v)),v.end());
	map<int,int> val;
	rep(i,0,SZ(v)) val[v[i]]=i+1;
	rep(i,1,q+1) {
		if (z[i]<=x[i]+y[i]) c1[++q1]={x[i],y[i],z[i],i};
		else c2[++q2]={x[i],y[i],z[i],i};
	}
	rep(i,1,n+1) c1[++q1]={s[i],t[i],0,0};
	rep(i,1,n+1) c2[++q2]={s[i],t[i],s[i]+t[i],0};
	sort(c1+1,c1+q1+1,[&](st A,st B) { if (A.x!=B.x) return A.x>B.x; return A.id<B.id; });
	sort(c2+1,c2+q2+1,[&](st A,st B) { if (A.z!=B.z) return A.z>B.z; return A.id<B.id; });
	fenwick ds;
	int cnt=0;
	rep(i,1,q1+1) {
		if (c1[i].id==0) {
			cnt++;
			ds.modify(val[c1[i].y],1);
		} else {
			ans[c1[i].id]=cnt-ds.query(val[c1[i].y]);
		}
	}
	cnt=0;
	fenwick ds1,ds2;
	rep(i,1,q2+1) {
		if (c2[i].id==0) {
			cnt++;
			ds1.modify(val[c2[i].x],1);
			ds2.modify(val[c2[i].y],1);
		} else {
			ans[c2[i].id]=cnt-ds1.query(val[c2[i].x])-ds2.query(val[c2[i].y]);
		}
	}
	rep(i,1,q+1) printf("%d\n",ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
examination.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |  rep(i,1,n+1) scanf("%d%d",s+i,t+i),v.pb(s[i]),v.pb(t[i]),v.pb(s[i]+t[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   46 |  rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),v.pb(x[i]),v.pb(y[i]),v.pb(z[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6220 KB Output is correct
2 Correct 3 ms 6220 KB Output is correct
3 Correct 3 ms 6188 KB Output is correct
4 Correct 2 ms 6220 KB Output is correct
5 Correct 4 ms 6188 KB Output is correct
6 Correct 3 ms 6220 KB Output is correct
7 Correct 15 ms 7424 KB Output is correct
8 Correct 10 ms 7480 KB Output is correct
9 Correct 10 ms 7500 KB Output is correct
10 Correct 9 ms 7088 KB Output is correct
11 Correct 8 ms 7196 KB Output is correct
12 Correct 5 ms 6604 KB Output is correct
13 Correct 10 ms 7372 KB Output is correct
14 Correct 10 ms 7364 KB Output is correct
15 Correct 9 ms 7352 KB Output is correct
16 Correct 7 ms 6860 KB Output is correct
17 Correct 9 ms 6988 KB Output is correct
18 Correct 5 ms 6604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 24264 KB Output is correct
2 Correct 273 ms 25132 KB Output is correct
3 Correct 274 ms 25060 KB Output is correct
4 Correct 150 ms 22340 KB Output is correct
5 Correct 199 ms 22324 KB Output is correct
6 Correct 100 ms 17256 KB Output is correct
7 Correct 237 ms 24832 KB Output is correct
8 Correct 261 ms 24864 KB Output is correct
9 Correct 227 ms 24536 KB Output is correct
10 Correct 177 ms 21792 KB Output is correct
11 Correct 148 ms 21864 KB Output is correct
12 Correct 81 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 24264 KB Output is correct
2 Correct 273 ms 25132 KB Output is correct
3 Correct 274 ms 25060 KB Output is correct
4 Correct 150 ms 22340 KB Output is correct
5 Correct 199 ms 22324 KB Output is correct
6 Correct 100 ms 17256 KB Output is correct
7 Correct 237 ms 24832 KB Output is correct
8 Correct 261 ms 24864 KB Output is correct
9 Correct 227 ms 24536 KB Output is correct
10 Correct 177 ms 21792 KB Output is correct
11 Correct 148 ms 21864 KB Output is correct
12 Correct 81 ms 16936 KB Output is correct
13 Correct 293 ms 26536 KB Output is correct
14 Correct 265 ms 25444 KB Output is correct
15 Correct 258 ms 25016 KB Output is correct
16 Correct 175 ms 22916 KB Output is correct
17 Correct 196 ms 22948 KB Output is correct
18 Correct 99 ms 17344 KB Output is correct
19 Correct 271 ms 26576 KB Output is correct
20 Correct 261 ms 26024 KB Output is correct
21 Correct 269 ms 26508 KB Output is correct
22 Correct 177 ms 21728 KB Output is correct
23 Correct 144 ms 21820 KB Output is correct
24 Correct 87 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 6220 KB Output is correct
2 Correct 3 ms 6220 KB Output is correct
3 Correct 3 ms 6188 KB Output is correct
4 Correct 2 ms 6220 KB Output is correct
5 Correct 4 ms 6188 KB Output is correct
6 Correct 3 ms 6220 KB Output is correct
7 Correct 15 ms 7424 KB Output is correct
8 Correct 10 ms 7480 KB Output is correct
9 Correct 10 ms 7500 KB Output is correct
10 Correct 9 ms 7088 KB Output is correct
11 Correct 8 ms 7196 KB Output is correct
12 Correct 5 ms 6604 KB Output is correct
13 Correct 10 ms 7372 KB Output is correct
14 Correct 10 ms 7364 KB Output is correct
15 Correct 9 ms 7352 KB Output is correct
16 Correct 7 ms 6860 KB Output is correct
17 Correct 9 ms 6988 KB Output is correct
18 Correct 5 ms 6604 KB Output is correct
19 Correct 276 ms 24264 KB Output is correct
20 Correct 273 ms 25132 KB Output is correct
21 Correct 274 ms 25060 KB Output is correct
22 Correct 150 ms 22340 KB Output is correct
23 Correct 199 ms 22324 KB Output is correct
24 Correct 100 ms 17256 KB Output is correct
25 Correct 237 ms 24832 KB Output is correct
26 Correct 261 ms 24864 KB Output is correct
27 Correct 227 ms 24536 KB Output is correct
28 Correct 177 ms 21792 KB Output is correct
29 Correct 148 ms 21864 KB Output is correct
30 Correct 81 ms 16936 KB Output is correct
31 Correct 293 ms 26536 KB Output is correct
32 Correct 265 ms 25444 KB Output is correct
33 Correct 258 ms 25016 KB Output is correct
34 Correct 175 ms 22916 KB Output is correct
35 Correct 196 ms 22948 KB Output is correct
36 Correct 99 ms 17344 KB Output is correct
37 Correct 271 ms 26576 KB Output is correct
38 Correct 261 ms 26024 KB Output is correct
39 Correct 269 ms 26508 KB Output is correct
40 Correct 177 ms 21728 KB Output is correct
41 Correct 144 ms 21820 KB Output is correct
42 Correct 87 ms 16936 KB Output is correct
43 Incorrect 569 ms 49160 KB Output isn't correct
44 Halted 0 ms 0 KB -