답안 #750535

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
750535 2023-05-29T16:19:02 Z mars4 Examination (JOI19_examination) C++17
100 / 100
1327 ms 125580 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#define ff              first
#define ss              second
#define ll              int64_t
#define ld              long double
#define nl              cout<<"\n"
#define i128            __int128_t
#define all(v)          v.begin(),v.end()
#define mset(a,v)       memset((a),(v),sizeof(a))
#define forn(i,a,b)     for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b)     for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()        ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

#define mod         1'000'000'007
#define mod2        998'244'353 
#define inf         1'000'000'000'000'007
#define pi          3.14159265358979323846

template<class key,class cmp=std::less<key>>
using ordered_set=tree<key,null_type,cmp,rb_tree_tag,tree_order_statistics_node_update>;

template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p)        {return out<<"("<<p.ff<<", "<<p.ss<<")";}
template<class T> ostream& operator<<(ostream& out,vector<T> &v)                {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,deque<T> &v)                 {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,set<T> &s)                   {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class T> ostream& operator<<(ostream& out,ordered_set<T> &s)           {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m)         {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";}

void dbg_out() {cerr<<"]\n";}
template<typename Head,typename... Tail> 
void dbg_out(Head H,Tail... T) {cerr<<H;if(sizeof...(Tail))cerr<<", ";dbg_out(T...);}
#ifdef LOCAL
#define dbg(...) cerr<<"["<<#__VA_ARGS__<<"] = [",dbg_out(__VA_ARGS__)
#else
#define dbg(...)
#endif

//---------------------------------mars4---------------------------------

template<class T> class MergeSortTree
{
	ll N;

	ll lesser_than(ll i,ll val)
	{
		ll res=0;
		for(;i;i-=i&(-i))
		{
			res+=fentree[i].order_of_key(val);
		}
		return res;
	}

	ll greater_than(ll i,ll val)
	{
		ll res=0;
		for(;i;i-=i&(-i))
		{
			res+=(ll)fentree[i].size()-fentree[i].order_of_key(val+1);
		}
		return res;
	}

	public:
	vector<ordered_set<T,less_equal<T>>> fentree;

	void init(ll n)
	{
		N=n;
		fentree=vector<ordered_set<T,less_equal<T>>>(N+1);
	}

	void build(vector<ll> &a)
	{
		for(ll i=1;i<=N;i++)
		{
			fentree[i].insert(a[i-1]);
			if(i+(i&-i)<=N)
			{
				for(ll j:fentree[i])
				{
					fentree[i+(i&-i)].insert(j);
				}
			}
		}
	}

	void update(ll i,ll nval)
	{
		for(i++;i<=N;i+=i&(-i))
		{
			fentree[i].insert(nval);
		}
	}

	ll lesser_than(ll l,ll r,ll val)
	{
		return lesser_than(r+1,val)-lesser_than(l,val);
	}

	ll greater_than(ll l,ll r,ll val)
	{
		if(l>r)
		{
			return 0;
		}
		return greater_than(r+1,val)-greater_than(l,val);
	}

	ll count(ll l,ll r,ll val)
	{
		ll len=r-l+1;
		ll gt=greater_than(l,r,val);
		ll lt=lesser_than(l,r,val);
		return len-gt-lt;
	}
};

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n>>m;
	vector<array<ll,3>> a(n);
	vector<array<ll,4>> q(n);
	vector<ll> vl;
	vector<ll> vr;
	for(auto &[l,r,tot]:a)
	{
		cin>>l>>r;
		tot=l+r;
		vl.push_back(l);
		vr.push_back(r);
	}
	sort(all(vl));
	sort(all(vr));
	for(auto &[l,r,tot]:a)
	{
		l=lower_bound(all(vl),l)-vl.begin();
		r=lower_bound(all(vr),r)-vr.begin();
	}
	forn(i,0,m)
	{
		auto &[l,r,tot,ind]=q[i];
		cin>>l>>r>>tot;
		l=lower_bound(all(vl),l)-vl.begin();
		r=lower_bound(all(vr),r)-vr.begin();
		ind=i;
	}
	sort(all(a),greater<array<ll,3>>());
	sort(all(q),greater<array<ll,4>>());
	MergeSortTree<ll> mt;
	mt.init(n);
	j=0;
	vector<ll> ans(m);
	forn(i,0,m)
	{
		while(j<n and a[j][0]>=q[i][0])
		{
			mt.update(a[j][1],a[j][2]);
			j++;
		}
		ans[q[i][3]]=mt.greater_than(q[i][1],n-1,q[i][2]-1);
	}
	for(ll i:ans)
	{
		cout<<i<<"\n";
	}
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}

Compilation message

examination.cpp: In function 'int main()':
examination.cpp:128:5: warning: unused variable 'z' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |     ^
examination.cpp:128:11: warning: unused variable 't' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |           ^
examination.cpp:128:13: warning: unused variable 'k' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |             ^
examination.cpp:128:15: warning: unused variable 'i' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |               ^
examination.cpp:128:19: warning: unused variable 'l' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                   ^
examination.cpp:128:21: warning: unused variable 'd' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                     ^
examination.cpp:128:23: warning: unused variable 'h' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                       ^
examination.cpp:128:25: warning: unused variable 'r' [-Wunused-variable]
  128 |  ll z,n,m,t,k,i,j,l,d,h,r;
      |                         ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 2076 KB Output is correct
8 Correct 11 ms 2120 KB Output is correct
9 Correct 9 ms 2124 KB Output is correct
10 Correct 10 ms 2260 KB Output is correct
11 Correct 8 ms 2000 KB Output is correct
12 Correct 8 ms 2132 KB Output is correct
13 Correct 10 ms 2028 KB Output is correct
14 Correct 9 ms 2132 KB Output is correct
15 Correct 9 ms 2016 KB Output is correct
16 Correct 8 ms 2004 KB Output is correct
17 Correct 15 ms 3144 KB Output is correct
18 Correct 13 ms 3076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 825 ms 73788 KB Output is correct
2 Correct 846 ms 73960 KB Output is correct
3 Correct 835 ms 73980 KB Output is correct
4 Correct 543 ms 77968 KB Output is correct
5 Correct 474 ms 73848 KB Output is correct
6 Correct 409 ms 79160 KB Output is correct
7 Correct 1010 ms 74012 KB Output is correct
8 Correct 858 ms 74084 KB Output is correct
9 Correct 770 ms 74236 KB Output is correct
10 Correct 371 ms 74060 KB Output is correct
11 Correct 868 ms 125420 KB Output is correct
12 Correct 1295 ms 125300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 825 ms 73788 KB Output is correct
2 Correct 846 ms 73960 KB Output is correct
3 Correct 835 ms 73980 KB Output is correct
4 Correct 543 ms 77968 KB Output is correct
5 Correct 474 ms 73848 KB Output is correct
6 Correct 409 ms 79160 KB Output is correct
7 Correct 1010 ms 74012 KB Output is correct
8 Correct 858 ms 74084 KB Output is correct
9 Correct 770 ms 74236 KB Output is correct
10 Correct 371 ms 74060 KB Output is correct
11 Correct 868 ms 125420 KB Output is correct
12 Correct 1295 ms 125300 KB Output is correct
13 Correct 1045 ms 74292 KB Output is correct
14 Correct 956 ms 74184 KB Output is correct
15 Correct 870 ms 74188 KB Output is correct
16 Correct 657 ms 78828 KB Output is correct
17 Correct 542 ms 74128 KB Output is correct
18 Correct 423 ms 80056 KB Output is correct
19 Correct 1034 ms 74208 KB Output is correct
20 Correct 972 ms 74116 KB Output is correct
21 Correct 1174 ms 74108 KB Output is correct
22 Correct 367 ms 73964 KB Output is correct
23 Correct 872 ms 125316 KB Output is correct
24 Correct 1233 ms 125284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 10 ms 2076 KB Output is correct
8 Correct 11 ms 2120 KB Output is correct
9 Correct 9 ms 2124 KB Output is correct
10 Correct 10 ms 2260 KB Output is correct
11 Correct 8 ms 2000 KB Output is correct
12 Correct 8 ms 2132 KB Output is correct
13 Correct 10 ms 2028 KB Output is correct
14 Correct 9 ms 2132 KB Output is correct
15 Correct 9 ms 2016 KB Output is correct
16 Correct 8 ms 2004 KB Output is correct
17 Correct 15 ms 3144 KB Output is correct
18 Correct 13 ms 3076 KB Output is correct
19 Correct 825 ms 73788 KB Output is correct
20 Correct 846 ms 73960 KB Output is correct
21 Correct 835 ms 73980 KB Output is correct
22 Correct 543 ms 77968 KB Output is correct
23 Correct 474 ms 73848 KB Output is correct
24 Correct 409 ms 79160 KB Output is correct
25 Correct 1010 ms 74012 KB Output is correct
26 Correct 858 ms 74084 KB Output is correct
27 Correct 770 ms 74236 KB Output is correct
28 Correct 371 ms 74060 KB Output is correct
29 Correct 868 ms 125420 KB Output is correct
30 Correct 1295 ms 125300 KB Output is correct
31 Correct 1045 ms 74292 KB Output is correct
32 Correct 956 ms 74184 KB Output is correct
33 Correct 870 ms 74188 KB Output is correct
34 Correct 657 ms 78828 KB Output is correct
35 Correct 542 ms 74128 KB Output is correct
36 Correct 423 ms 80056 KB Output is correct
37 Correct 1034 ms 74208 KB Output is correct
38 Correct 972 ms 74116 KB Output is correct
39 Correct 1174 ms 74108 KB Output is correct
40 Correct 367 ms 73964 KB Output is correct
41 Correct 872 ms 125316 KB Output is correct
42 Correct 1233 ms 125284 KB Output is correct
43 Correct 1028 ms 74048 KB Output is correct
44 Correct 1022 ms 74064 KB Output is correct
45 Correct 910 ms 74020 KB Output is correct
46 Correct 620 ms 77140 KB Output is correct
47 Correct 543 ms 74116 KB Output is correct
48 Correct 432 ms 79920 KB Output is correct
49 Correct 1155 ms 74232 KB Output is correct
50 Correct 872 ms 74104 KB Output is correct
51 Correct 882 ms 74220 KB Output is correct
52 Correct 436 ms 73892 KB Output is correct
53 Correct 1327 ms 125580 KB Output is correct