답안 #485978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
485978 2021-11-10T03:23:15 Z MilosMilutinovic Examination (JOI19_examination) C++14
0 / 100
1069 ms 69276 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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)


const int N=301000;
int n,q,s[N],t[N],x[N],y[N],z[N],ans[N];
int p[N],qs[N];
ordered_set 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) {
		res+=SZ(c[x])-c[x].order_of_key(y);
	}
	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:50:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |  scanf("%d%d",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~
examination.cpp:51:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |  rep(i,1,n+1) scanf("%d%d",s+i,t+i),p[i]=i,v.pb(s[i]);
      |               ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:52:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |  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 20 ms 23884 KB Output is correct
2 Correct 20 ms 23884 KB Output is correct
3 Correct 17 ms 23816 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 18 ms 23884 KB Output is correct
7 Correct 25 ms 25064 KB Output is correct
8 Correct 28 ms 25172 KB Output is correct
9 Correct 26 ms 25164 KB Output is correct
10 Incorrect 22 ms 24728 KB Output isn't correct
11 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1069 ms 69276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1069 ms 69276 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 20 ms 23884 KB Output is correct
2 Correct 20 ms 23884 KB Output is correct
3 Correct 17 ms 23816 KB Output is correct
4 Correct 17 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 18 ms 23884 KB Output is correct
7 Correct 25 ms 25064 KB Output is correct
8 Correct 28 ms 25172 KB Output is correct
9 Correct 26 ms 25164 KB Output is correct
10 Incorrect 22 ms 24728 KB Output isn't correct
11 Halted 0 ms 0 KB -