# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
529893 |
2022-02-24T00:22:20 Z |
i_am_noob |
Colors (RMI18_colors) |
C++17 |
|
653 ms |
90076 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops")
#define ll long long
#define int ll
#define ull unsigned ll
#define ld long double
#define rep(a) rep1(i,a)
#define rep1(i,a) rep2(i,0,a)
#define rep2(i,b,a) for(int i=(b); i<((int)(a)); i++)
#define rep3(i,b,a) for(int i=(b); i>=((int)(a)); i--)
#define chkmin(a,b) (a=min(a,b))
#define chkmax(a,b) (a=max(a,b))
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define pb push_back
//#define inf 1010000000
#define inf 4000000000000000000
#define eps 1e-9
#define sz(a) ((int)a.size())
#define pow2(x) (1ll<<(x))
#define ceiling(a,b) (((a)+(b)-1)/(b))
#define print0(a) cout << (a) << ' '
#define ykh mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#ifdef i_am_noob
#define bug(...) cerr << "#" << __LINE__ << ' ' << #__VA_ARGS__ << "- ", _do(__VA_ARGS__)
template<typename T> void _do(vector<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(unordered_set<T> x){for(auto i: x) cerr << i << ' ';cerr << "\n";}
template<typename T> void _do(T && x) {cerr << x << endl;}
template<typename T, typename ...S> void _do(T && x, S&&...y) {cerr << x << ", "; _do(y...);}
#else
#define bug(...) 777771449
#endif
template<typename T> void print(T && x) {cout << x << "\n";}
template<typename T, typename... S> void print(T && x, S&&... y) {cout << x << ' ';print(y...);}
const int Mod=1000000007,Mod2=998244353;
const int MOD=Mod2;
template <int mod>
struct Modint{
int val;
Modint(int _val=0){val=_val%mod;if(val<0) val+=mod;}
Modint operator +(const Modint& o) const {
Modint res;
res.val=val+o.val;
if(res.val>=mod) res.val-=mod;
return res;
}
Modint operator +(const int& o) const {return Modint(val+o);}
Modint operator -() const {
Modint res;
res.val=-val;
if(res.val<0) res.val+=mod;
return res;
}
Modint operator -(const Modint& o) const {
Modint res;
res.val=val-o.val;
if(res.val<0) res.val+=mod;
return res;
}
Modint operator -(const int& o) const {return Modint(val-o);}
Modint operator *(const Modint& o) const {return Modint(val*o.val);}
Modint operator *(const int& o) const {return Modint(val*(o%mod));}
Modint operator +=(const Modint& o){*this=(*this)+o;return *this;}
Modint operator -=(const Modint& o){*this=(*this)-o;return *this;}
Modint operator *=(const Modint& o){*this=(*this)*o;return *this;}
Modint Pow(int b) const {
Modint tmp(val),ret(1);
while(b){
if(b&1) ret*=tmp;
b>>=1;tmp*=tmp;
}
return ret;
}
Modint Pow(const Modint& a, int b) const {return a.Pow(b);}
inline Modint inv() const {return (*this).Pow(mod-2);}
Modint operator /(const Modint& o) const {return *this*o.inv();}
Modint operator /(const int& o) const {return *this*Modint(o).inv();}
bool operator ==(const Modint& o) const {return val==o.val;}
};
template<int mod>
ostream& operator << (ostream& o, Modint<mod> x){return o << x.val;}
template<int mod>
Modint<mod> operator +(const int& x, const Modint<mod>& y){return Modint<mod>(x+y.val);}
template<int mod>
Modint<mod> operator -(const int& x, const Modint<mod>& y){return Modint<mod>(x-y.val);}
template<int mod>
Modint<mod> operator *(const int& x, const Modint<mod>& y){return Modint<mod>(x%mod*y.val);}
#define modint Modint<MOD>
vector<modint> inv,fac,invfac;
void init_comb(int N){
inv.resize(N),fac.resize(N),invfac.resize(N);
inv[1]=1,fac[0]=1,invfac[0]=1;
rep2(i,2,N) inv[i]=inv[MOD%i]*(MOD-MOD/i);
rep2(i,1,N) fac[i]=fac[i-1]*i;
rep2(i,1,N) invfac[i]=invfac[i-1]*inv[i];
}
inline modint C(int n, int m){return m>n||m<0?modint(0):fac[n]*invfac[m]*invfac[n-m];}
inline modint H(int n, int m){return C(n+m-1,n);}
const int maxn=150005,maxm=5,maxk=7777714;
//i_am_noob
#define wiwihorz
int par[maxn],siz[maxn];
vector<pii> ops;
int Find(int x){return x==par[x]?x:Find(par[x]);}
void Union(int x, int y){
x=Find(x),y=Find(y);
if(x==y) return;
if(siz[x]<siz[y]) swap(x,y);
par[y]=x;
siz[x]+=siz[y];
ops.pb({x,y});
}
void undo(){
if(ops.empty()) return;
par[ops.back().second]=ops.back().second;
siz[ops.back().first]-=siz[ops.back().second];
ops.pop_back();
}
vector<vector<pii>> node(maxn*4);
void build(int k, int l, int r){
node[k].clear();
if(l==r) return;
int mid=l+r>>1;
build(k<<1,l,mid),build(k<<1|1,mid+1,r);
}
void Insert(int k, int l, int r, int ql, int qr, int u, int v){
if(l>qr||r<ql) return;
if(ql<=l&&qr>=r){
node[k].pb({u,v});
return;
}
int mid=l+r>>1;
Insert(k<<1,l,mid,ql,qr,u,v),Insert(k<<1|1,mid+1,r,ql,qr,u,v);
}
int n,m,l[maxn],r[maxn];
vector<vector<int>> in(maxn),out(maxn);
bool flag;
void solve(int k, int l, int r){
for(auto [x,y]: node[k]) Union(x,y);
if(l==r){
vector<int> vec;
for(auto i: out[l]) vec.pb(Find(i));
sort(all(vec));
vec.resize(unique(all(vec))-vec.begin());
for(auto i: in[l]) if(!binary_search(all(vec),Find(i))) flag=0;
rep(sz(node[k])) undo();
return;
}
int mid=l+r>>1;
solve(k<<1,l,mid),solve(k<<1|1,mid+1,r);
rep(sz(node[k])) undo();
}
void orzck(){
cin >> n >> m;
rep(n) cin >> l[i];
rep(n) cin >> r[i];
rep(n) l[i]=n-l[i],r[i]=n-r[i];
rep(n) in[i].clear(),out[i].clear();
rep(n) par[i]=i,siz[i]=1;
rep(n) in[r[i]].pb(i),out[l[i]].pb(i);
build(1,0,n-1);
rep(m){
int u,v;
cin >> u >> v;
u--,v--;
int L=max(l[u],l[v]),R=min(r[u],r[v]);
if(L<=R) Insert(1,0,n-1,L,R,u,v);
}
rep(n) if(l[i]>r[i]){
print(0);
return;
}
flag=1;
solve(1,0,n-1);
print(flag);
}
signed main(){
ios_base::sync_with_stdio(0),cin.tie(0);
// #ifdef i_am_noob
// freopen("input1.txt","r",stdin);
// freopen("output1.txt","w",stdout);
// freopen("output2.txt","w",stderr);
// #endif
cout << fixed << setprecision(15);
int t;
#ifdef wiwihorz
cin >> t;
#else
t=1;
#endif
ld start=clock();
while(t--) orzck();
bug((clock()-start)/CLOCKS_PER_SEC);
return 0;
}
Compilation message
colors.cpp: In function 'void build(long long int, long long int, long long int)':
colors.cpp:131:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
131 | int mid=l+r>>1;
| ~^~
colors.cpp: In function 'void Insert(long long int, long long int, long long int, long long int, long long int, long long int, long long int)':
colors.cpp:141:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
141 | int mid=l+r>>1;
| ~^~
colors.cpp: In function 'void solve(long long int, long long int, long long int)':
colors.cpp:160:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
160 | int mid=l+r>>1;
| ~^~
colors.cpp: In function 'int main()':
colors.cpp:34:18: warning: statement has no effect [-Wunused-value]
34 | #define bug(...) 777771449
| ^~~~~~~~~
colors.cpp:206:5: note: in expansion of macro 'bug'
206 | bug((clock()-start)/CLOCKS_PER_SEC);
| ^~~
colors.cpp:204:8: warning: unused variable 'start' [-Wunused-variable]
204 | ld start=clock();
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
22924 KB |
Output is correct |
2 |
Correct |
32 ms |
22216 KB |
Output is correct |
3 |
Correct |
14 ms |
22012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
23492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
23016 KB |
Output is correct |
2 |
Correct |
33 ms |
22076 KB |
Output is correct |
3 |
Correct |
14 ms |
21980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
23016 KB |
Output is correct |
2 |
Correct |
33 ms |
22076 KB |
Output is correct |
3 |
Correct |
14 ms |
21980 KB |
Output is correct |
4 |
Correct |
149 ms |
24640 KB |
Output is correct |
5 |
Correct |
379 ms |
54932 KB |
Output is correct |
6 |
Correct |
653 ms |
90076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
22924 KB |
Output is correct |
2 |
Correct |
32 ms |
22216 KB |
Output is correct |
3 |
Correct |
14 ms |
22012 KB |
Output is correct |
4 |
Correct |
69 ms |
23016 KB |
Output is correct |
5 |
Correct |
33 ms |
22076 KB |
Output is correct |
6 |
Correct |
14 ms |
21980 KB |
Output is correct |
7 |
Correct |
75 ms |
23112 KB |
Output is correct |
8 |
Correct |
34 ms |
22180 KB |
Output is correct |
9 |
Correct |
19 ms |
21956 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
129 ms |
24680 KB |
Output is correct |
2 |
Correct |
388 ms |
56708 KB |
Output is correct |
3 |
Correct |
372 ms |
67584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
42 ms |
22472 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
22924 KB |
Output is correct |
2 |
Correct |
32 ms |
22216 KB |
Output is correct |
3 |
Correct |
14 ms |
22012 KB |
Output is correct |
4 |
Correct |
63 ms |
23492 KB |
Output is correct |
5 |
Correct |
69 ms |
23016 KB |
Output is correct |
6 |
Correct |
33 ms |
22076 KB |
Output is correct |
7 |
Correct |
14 ms |
21980 KB |
Output is correct |
8 |
Correct |
149 ms |
24640 KB |
Output is correct |
9 |
Correct |
379 ms |
54932 KB |
Output is correct |
10 |
Correct |
653 ms |
90076 KB |
Output is correct |
11 |
Correct |
75 ms |
23112 KB |
Output is correct |
12 |
Correct |
34 ms |
22180 KB |
Output is correct |
13 |
Correct |
19 ms |
21956 KB |
Output is correct |
14 |
Correct |
129 ms |
24680 KB |
Output is correct |
15 |
Correct |
388 ms |
56708 KB |
Output is correct |
16 |
Correct |
372 ms |
67584 KB |
Output is correct |
17 |
Incorrect |
42 ms |
22472 KB |
Output isn't correct |
18 |
Halted |
0 ms |
0 KB |
- |