답안 #121950

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121950 2019-06-27T09:12:23 Z claudy Examination (JOI19_examination) C++14
0 / 100
3000 ms 511828 KB
//# pragma GCC optimize("Ofast,no-stack-protector")
//# pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
# pragma GCC optimize("Ofast")
# pragma GCC optimization ("unroll-loops")
# include "bits/stdc++.h"
std::pair<int,int> DR[] = {{-1,0},{0,1},{1,0},{0,-1},{-1,1},{-1,-1},{1,1},{1,-1}};
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define rcg(s) cout << s;exit(0)
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define all(s) s.begin(),s.end()
# define sz(x) (int)((x).size())
//# define int ll
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

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;

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# define LOCAL
# define sim template < class c
# define ris return * this
# define dor > debug & operator <<
# define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define show(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int gcd(int a, int b)
{
if(b) return gcd(b,a%b);
return a;
}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

set<int>sk,compress;
map<int,vector<int>>offline,queries;
map<int,int>val;
int mytime = 1;
ordered_set T[1 << 22];
int ans[1 << 17],x[1 << 17],y[1 << 17],z[1 << 17],n,q,s[1 << 17],t[1 << 17];

void upd(int nod,int l,int r,int pos,int val)
{
	T[nod].insert(mp(val,mytime++));
	if(l == r) return ;
	int mid = l + r >> 1;
	if(pos <= mid) upd(nod << 1,l,mid,pos,val);
	else upd(nod << 1 | 1,mid + 1,r,pos,val);
}

int qry(int nod,int tl,int tr,int l,int r,int val)
{
	if(l > r) return 0;
	if(tl == l && tr == r)
	{
		val--;
		auto it = T[nod].upper_bound(mp(val,1e9));
		if(it == T[nod].end()) return 0;
		return sz(T[nod]) - T[nod].order_of_key(*it);
	}
	int mid = tl + tr >> 1;
	return qry(nod << 1,tl,mid,l,min(mid,r),val) + qry(nod << 1 | 1,mid + 1,tr,max(mid + 1,l),r,val);
}

int32_t main(){_
	//freopen("input","r",stdin);
	cin >> n >> q;
	for(int i = 1;i <= n;i++)
	{
		cin >> s[i] >> t[i];
		compress.insert(s[i]);
		compress.insert(t[i]);
		compress.insert(s[i] + t[i]);
		offline[-s[i]].pb(i);
		sk.insert(s[i]);
	}
	for(int i = 1;i <= q;i++)
	{
		cin >> x[i] >> y[i] >> z[i];
		auto it = sk.upper_bound(x[i]);
		if(it != sk.end())
		{
			queries[-(*it)].pb(i);
		}
		compress.insert(x[i]);
		compress.insert(y[i]);
		compress.insert(z[i]);
	}
	int k = 1;
	for(auto it : compress)
	{
		val[it] = k++;
	}
	k--;
	for(auto it : offline)
	{
		for(auto itt : it.second) upd(1,1,k,val[t[itt]],val[t[itt] + s[itt]]);
		for(auto itt : queries[it.first])
		{
			ans[itt] = qry(1,1,k,val[y[itt]],k,val[z[itt]]);
		}
	}
	for(int i = 1;i <= q;i++)
	{
		cout << ans[i] << '\n';
	}
	return 0;
}







Compilation message

examination.cpp:4:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 # pragma GCC optimization ("unroll-loops")
 
examination.cpp: In function 'void upd(int, int, int, int, int)':
examination.cpp:74:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = l + r >> 1;
            ~~^~~
examination.cpp: In function 'int qry(int, int, int, int, int, int)':
examination.cpp:89:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  int mid = tl + tr >> 1;
            ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 394440 KB Output is correct
2 Correct 473 ms 394532 KB Output is correct
3 Correct 472 ms 394400 KB Output is correct
4 Correct 478 ms 394360 KB Output is correct
5 Correct 455 ms 394476 KB Output is correct
6 Correct 464 ms 394360 KB Output is correct
7 Correct 515 ms 399864 KB Output is correct
8 Correct 498 ms 399800 KB Output is correct
9 Correct 508 ms 399736 KB Output is correct
10 Correct 479 ms 399100 KB Output is correct
11 Incorrect 512 ms 398456 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3067 ms 511828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3067 ms 511828 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 394440 KB Output is correct
2 Correct 473 ms 394532 KB Output is correct
3 Correct 472 ms 394400 KB Output is correct
4 Correct 478 ms 394360 KB Output is correct
5 Correct 455 ms 394476 KB Output is correct
6 Correct 464 ms 394360 KB Output is correct
7 Correct 515 ms 399864 KB Output is correct
8 Correct 498 ms 399800 KB Output is correct
9 Correct 508 ms 399736 KB Output is correct
10 Correct 479 ms 399100 KB Output is correct
11 Incorrect 512 ms 398456 KB Output isn't correct
12 Halted 0 ms 0 KB -