답안 #485977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485977 2021-11-10T03:18:42 Z MilosMilutinovic Examination (JOI19_examination) C++14
2 / 100
3000 ms 59616 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=301000;
int n,q,s[N],t[N],x[N],y[N],z[N],ans[N];
int p[N],qs[N];
multiset<int> c[N];

void modify(int x,int y) {
	for (;x;x-=x&-x) c[x].insert(y);
}

int get(int x,int y) {
	int res=0;
	for (;x<N;x+=x&-x) {
		auto it=c[x].lower_bound(y);
		res+=(int)(distance(it,c[x].end()));
	}
	return res;
}

int main() {
	VI v;
	scanf("%d%d",&n,&q);
	rep(i,1,n+1) scanf("%d%d",s+i,t+i),p[i]=i,v.pb(s[i]);
	rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),qs[i]=i,v.pb(x[i]);
	sort(p+1,p+n+1,[&](int i,int j) { return s[i]+t[i]>s[j]+t[j]; });
	sort(qs+1,qs+q+1,[&](int i,int j) { return z[i]>z[j]; });
	sort(all(v)); v.erase(unique(all(v)),v.end());
	map<int,int> val;
	rep(i,0,SZ(v)) val[v[i]]=i+1;
	int ptr=1;
	rep(i,1,q+1) {
		while (ptr<=n&&s[p[ptr]]+t[p[ptr]]>=z[qs[i]]) {
			modify(val[s[p[ptr]]],t[p[ptr]]); ptr++;
		}
		ans[qs[i]]=get(val[x[qs[i]]],y[qs[i]]);
	}
	rep(i,1,q+1) printf("%d\n",ans[i]);
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:43:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
examination.cpp:44:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  rep(i,1,n+1) scanf("%d%d",s+i,t+i),p[i]=i,v.pb(s[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~
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,q+1) scanf("%d%d%d",x+i,y+i,z+i),qs[i]=i,v.pb(x[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 6 ms 14440 KB Output is correct
3 Correct 9 ms 14444 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14444 KB Output is correct
6 Correct 6 ms 14500 KB Output is correct
7 Correct 37 ms 15848 KB Output is correct
8 Correct 29 ms 15840 KB Output is correct
9 Correct 28 ms 15900 KB Output is correct
10 Correct 30 ms 15788 KB Output is correct
11 Correct 24 ms 14936 KB Output is correct
12 Correct 24 ms 14880 KB Output is correct
13 Correct 40 ms 15792 KB Output is correct
14 Correct 42 ms 15820 KB Output is correct
15 Correct 37 ms 15872 KB Output is correct
16 Correct 19 ms 14796 KB Output is correct
17 Correct 24 ms 15864 KB Output is correct
18 Correct 10 ms 14668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3091 ms 59616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3091 ms 59616 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 14412 KB Output is correct
2 Correct 6 ms 14440 KB Output is correct
3 Correct 9 ms 14444 KB Output is correct
4 Correct 7 ms 14412 KB Output is correct
5 Correct 7 ms 14444 KB Output is correct
6 Correct 6 ms 14500 KB Output is correct
7 Correct 37 ms 15848 KB Output is correct
8 Correct 29 ms 15840 KB Output is correct
9 Correct 28 ms 15900 KB Output is correct
10 Correct 30 ms 15788 KB Output is correct
11 Correct 24 ms 14936 KB Output is correct
12 Correct 24 ms 14880 KB Output is correct
13 Correct 40 ms 15792 KB Output is correct
14 Correct 42 ms 15820 KB Output is correct
15 Correct 37 ms 15872 KB Output is correct
16 Correct 19 ms 14796 KB Output is correct
17 Correct 24 ms 15864 KB Output is correct
18 Correct 10 ms 14668 KB Output is correct
19 Execution timed out 3091 ms 59616 KB Time limit exceeded
20 Halted 0 ms 0 KB -