Submission #369243

# Submission time Handle Problem Language Result Execution time Memory
369243 2021-02-21T02:03:44 Z YJU Land of the Rainbow Gold (APIO17_rainbow) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector,Ofast")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
const ll MOD=1e9+7;
const ll MOD2=998244353;
const ll N=2e5+5;
const ld pi=acos(-1);
const ll INF=(1LL<<60);
#define SQ(i) ((i)*(i))
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define setp setprecision
#define lwb lower_bound
#define SZ(_a) (ll)_a.size()

struct Segment_Tree{
	struct node{
		ll sum;
		node *lc,*rc;
		node(){sum=0;lc=rc=0;}
	}*rt=new node();
	ll get(node *nd){
		return (nd?nd->sum:0);
	}
	void _ins(node *nd,ll l,ll r,ll to,ll del){
		if(l==r-1){nd->sum+=del;return ;}
		ll mid=(l+r)>>1;
		if(to<mid){
			if(!nd->lc)nd->lc=new node();
			_ins(nd->lc,l,mid,to,del);
		}else{
			if(!nd->rc)nd->rc=new node();
			_ins(nd->rc,mid,r,to,del);
		}
		nd->sum=get(nd->lc)+get(nd->rc);
	}
	ll _ask(node *nd,ll l,ll r,ll ql,ll qr){
		if(l>=ql&&r<=qr)return get(nd);
		if(l>=qr||r<=ql)return 0;
		ll mid=(l+r)>>1;
		return (nd->lc?_ask(nd->lc,l,mid,ql,qr):0LL)+(nd->rc?_ask(nd->rc,mid,r,ql,qr):0LL);
	}
	ll ask(ll ql,ll qr){
		return _ask(rt,0,N,ql,qr);
	}
	void ins(ll to,ll del){
		_ins(rt,0,N,to,del);
	}
}seg[4][4*N];

void ins(ll sid,ll id,ll l,ll r,ll tox,ll toy,ll del){
	seg[sid][id].ins(toy,del);
	if(l==r-1)return ;
	ll mid=(l+r)>>1;
	if(tox<mid){
		ins(sid,id*2,l,mid,tox,toy,del);
	}else{
		ins(sid,id*2+1,mid,r,tox,toy,del);
	}
}

ll query(ll sid,ll id,ll l,ll r,ll fl,ll fr,ll bl,ll br){
	if(l>=fl&&r<=fr){return seg[sid][id].ask(bl,br);}
	if(l>=fr||r<=fl)return 0;
	ll mid=(l+r)>>1;
	return query(sid,id*2,l,mid,fl,fr,bl,br)+query(sid,id*2+1,mid,r,fl,fr,bl,br);
}

//for [ar,br] [ac,bc]
//sid=0 V : [ar,br] [ac,bc]
//sid=1 VE : [ar,br) [ac,bc]
//sid=2 HE : [ar,br] [ac,bc)
//sid=3 F : [ar,br) [ac,bc)

ll mir,mxr,mic,mxc;

void init(int R,int C,int sr,int sc,int M,string S){
	vector<pll> v[4];
	mic=mxc=sc;
	mir=mxr=sr;
	for(int i=0;i<=M;i++){
		mic=min(mic,sc);mxc=max(mxc,sc);
		mir=min(mir,sr);mxr=max(mxr,sr);
		v[0].pb(mp(sr,sc));
		v[1].pb(mp(sr,sc));v[1].pb(mp(sr-1,sc));
		v[2].pb(mp(sr,sc));v[2].pb(mp(sr,sc-1));
		v[3].pb(mp(sr,sc));v[3].pb(mp(sr-1,sc));v[3].pb(mp(sr,sc-1));v[3].pb(mp(sr-1,sc-1));
		//
		if(i==M)break;
		if(S[i]=='N')--sr;
		if(S[i]=='S')++sr;
		if(S[i]=='W')--sc;
		if(S[i]=='E')++sc;
	}
	//unique
	for(int i=0;i<4;i++)sort(v[i].begin(),v[i].end()),v[i].erase(unique(v[i].begin(),v[i].end()),v[i].end());
	//
	for(int sid=0;sid<4;sid++){
		for(auto i:v[sid]){
			ins(sid,1,0,N,i.X,i.Y,-1);
		}
	}
}

ll colours(int ar,int ac,int br,int bc){
	ll ans=(br-ar+1)*(bc-ac+1)-(br-ar)*(bc-ac+1)-(br-ar+1)*(bc-ac)+(br-ar)*(bc-ac);
	ans+=query(0,1,0,N,ar,br+1,ac,bc+1);
	ans-=query(1,1,0,N,ar,br,ac,bc+1);
	ans-=query(2,1,0,N,ar,br+1,ac,bc);
	ans+=query(3,1,0,N,ar,br,ac,bc);
	ans+=(mxc<bc&&mic>ac&&mxr<br&&mir>ar?1:0);
	return ans;
}
/*
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	init(6,4,3,3,9,"NWESSWEWS");
	cout<<colours(2,3,2,3)<<"\n";
	cout<<colours(3,2,4,4)<<"\n";
	cout<<colours(5,3,6,4)<<"\n";
	cout<<colours(1,2,5,3)<<"\n";
	return 0;
}
//*/

Compilation message

rainbow.cpp: In function 'void init(int, int, int, int, int, std::string)':
rainbow.cpp:89:17: error: no matching function for call to 'min(ll&, int&)'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                 ^
rainbow.cpp:89:33: error: no matching function for call to 'max(ll&, int&)'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
rainbow.cpp:89:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   89 |   mic=min(mic,sc);mxc=max(mxc,sc);
      |                                 ^
rainbow.cpp:90:17: error: no matching function for call to 'min(ll&, int&)'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:198:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  198 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:198:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:246:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  246 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:246:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:17: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3444:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(std::initializer_list<_Tp>)'
 3444 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3444:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3450:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(std::initializer_list<_Tp>, _Compare)'
 3450 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3450:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:17: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                 ^
rainbow.cpp:90:33: error: no matching function for call to 'max(ll&, int&)'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:222:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  222 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:222:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                                 ^
In file included from /usr/include/c++/9/bits/char_traits.h:39,
                 from /usr/include/c++/9/ios:40,
                 from /usr/include/c++/9/istream:38,
                 from /usr/include/c++/9/sstream:38,
                 from /usr/include/c++/9/complex:45,
                 from /usr/include/c++/9/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:54,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algobase.h:268:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  268 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algobase.h:268:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:33: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3456:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(std::initializer_list<_Tp>)'
 3456 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3456:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                                 ^
In file included from /usr/include/c++/9/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/9/bits/stdc++.h:65,
                 from rainbow.cpp:1:
/usr/include/c++/9/bits/stl_algo.h:3462:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(std::initializer_list<_Tp>, _Compare)'
 3462 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/9/bits/stl_algo.h:3462:5: note:   template argument deduction/substitution failed:
rainbow.cpp:90:33: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   90 |   mir=min(mir,sr);mxr=max(mxr,sr);
      |                                 ^