義烏集訓7.12 contest 5題解
2021.7.11 Contest 題解
T1:
Description:
給定序列 \(a_1,a_2,...,a_n\) ,算出 \(t_1,t_2,...,t_n\) 滿足
- \(\forall t_i\gt0\);
- 對於所有的 \(i\) \((1\le i\lt n)\) , \(a_i*a_{i+1}*t_i*t_{i+1}\) 是完全平方數;
- \(\Pi_{i=1}^n t_i\) 最小。
請輸出最小的 \(\Pi_{i=1}^n t_i\)
Input:
第一行一個整數 \(n\) 。
第二行 \(n\) 個整數 \(a_1,a_2,...,a_n\)。
Output:
一行一個數表示答案。請輸出答案 mod \(10^9+7\)。
Sample1 Input:
3
2 3 6
Sample1 Output:
6
Hint:
對於所有資料,\(1\leq n \leq 10^5,1 \leq a_i \leq 10^6\)。
題目分析:
顯然,每個質因數可以分開考慮。
對於某一個質因數 \(p\) ,如果 \(a_i\) \((1\leq i<n)\)和 \(a_{i+1}\)中含有 \(p\) 的次數為奇數,則 \(t_i\) 與 \(t_{i+1}\) 中必有一個且僅有一個含有 \(p\) 作為因數;反之,\(t_i\) 和 \(t_{i+1}\)
於是,對於 \(p\) ,問題轉化為一個黑白染色的問題,強制 \(t_1\) 含有 \(p\) ,則 \(t_2,t_3,……,t_{n-1}\) 是否含有 \(p\) 都已確定,若含 \(p\) 的個數比不含 \(p\) 的個數多,則強制 \(t_1\) 不含有 \(p\),原來含 \(p\) 的 \(t_i\) 都不含 \(p\) ,不含 \(p\) 的 \(t_i\) 都含 \(p\) 。
總之就是個貪心選取的過程。
程式碼如下(馬蜂很醜,不喜勿噴)——
#include<bits/stdc++.h> #define N 100005 #define M 1000005 using namespace std; int n,tot,ans=1,S[M][2],pp[22],op[M],lst[M],pri[M],len[M],P[M][11],K[N][11],A[N][11],T[N],kk[M];bool ok[M];const int p=1e9+7; inline int power(int x,int y){int z=1;while(y){if(y&1) z=1ll*z*x%p;y>>=1,x=1ll*x*x%p;}return z;} struct FastIO{ static const int S=1048576; char buf[S],*L,*R;int stk[20],Top;~FastIO(){clear();} inline char nc(){return L==R&&(R=(L=buf)+fread(buf,1,S,stdin),L==R)?EOF:*L++;}inline void clear(){fwrite(buf,1,Top,stdout);Top=0;} inline void pc(char ch){Top==S&&(clear(),0);buf[Top++]=ch;}inline void endl(){pc('\n');} FastIO& operator >> (char&ch){while(ch=nc(),ch==' '||ch=='\n');return *this;} template<typename T>FastIO& operator >> (T&ret){ ret=0;int f=1;char ch=nc();while(ch<'0'||ch>'9'){if(ch=='-')f=-f;ch=nc();} while(ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=nc();}ret*=f;return *this; } FastIO& operator >> (char* s){int Len=0;char ch=nc();while(ch!='\n'){*(s+Len)=ch;Len++;ch=nc();}} template<typename T>FastIO& operator << (T x){ if(x<0){pc('-');x=-x;}do{stk[++stk[0]]=x%10;x/=10;}while(x); while(stk[0]) pc('0'+stk[stk[0]--]);return *this; } FastIO& operator << (char ch){pc(ch);return *this;} FastIO& operator << (string str){int Len=str.size()-1;for(stk[0]=0;Len>=0;Len--) stk[++stk[0]]=str[Len];while(stk[0]) pc(stk[stk[0]--]);return *this;} }fin,fout; int main(){ freopen("square.in","r",stdin);freopen("square.out","w",stdout); fin>>n;for(register int i=2;i<=M-5;i++){if(ok[i]) continue;pri[++tot]=i,P[i][++len[i]]=i;for(register int j=i*2;j<=M-5;j+=i) ok[j]=1,P[j][++len[j]]=i;} for(register int i=1,x;i<=n;i++){fin>>x;for(register int j=1;j<=len[x];j++){A[i][j]=P[x][j];int y=x;while(y%A[i][j]==0) y/=A[i][j],K[i][j]++;}T[i]=len[x];} for(register int i=1;i<n;i++){ int x=1,y=1,s=0;while(x<=T[i]&&y<=T[i+1]){ if(A[i][x]==A[i+1][y]){if((K[i][x]+K[i+1][y])&1) pp[++s]=A[i][x];x++,y++;} else if(A[i][x]<A[i+1][y]){if(K[i][x]&1) pp[++s]=A[i][x];x++;} else{if(K[i+1][y]&1) pp[++s]=A[i+1][y];y++;} } while(x<=T[i]){if(K[i][x]&1) pp[++s]=A[i][x];x++;} while(y<=T[i+1]){if(K[i+1][y]&1) pp[++s]=A[i+1][y];y++;} for(register int j=1;j<=s;j++) S[pp[j]][op[pp[j]]]+=(i-lst[pp[j]]),lst[pp[j]]=i,op[pp[j]]^=1;//,cout<<i<<' '<<pp[j]<<'\n'; } // cout<<S[2][0]<<' '<<S[2][1]<<'\n'; for(register int i=1;i<=tot;i++) S[pri[i]][op[pri[i]]]+=n-lst[pri[i]],ans=1ll*ans*power(pri[i],min(S[pri[i]][0],S[pri[i]][1]))%p;cout<<ans<<'\n';return 0; }
T2:
Description:
有一個 \(n×m\) 的棋盤。初始每個格子都是好的,之後每一秒會壞一個之前沒壞的格子。\(nm\) 秒過後所有格子都會壞完。
我們想知道,每一秒過後,有多少子矩形滿足其中的所有格子都是好的。
Input:
第一行兩個整數 \(n,m\)。
接下來 \(nm\) 行,每行表示一個壞掉的格子。
資料保證每個格子只會壞一次。
Output:
輸出 \(nm\) 行。第 \(i\) 行表示前 \(i\) 個格子壞掉後有多少子矩形是好的。
Sample1 Input:
2 2
1 1
2 1
1 2
2 2
Sample1 Output:
5
3
1
0
Hint:
對於 \(100\%\) 的資料,滿足 \(1 \leq n,m \leq 500\)。
題目分析:
我們考慮壞一個格子,有多少個子矩形由好的變為壞的。我們維護一個 \(u_{i,j}\) 表示格子 \((i,j)\) 往上第一個壞格子的位置以及一個 \(d_{i,j}\) 表示格子 \((i,j)\) 往下第一個壞格子的位置。那麼我們對於每個格子可以 \(O(m^2)\) 的暴力更新答案,由於跑不滿故能通過此題(說不定能吊打標算
當然,正解和這個演算法只差一步,我們僅需維護一個字首和就能將複雜度優化到 \(O(n^2m)\)。
注意:我的程式碼對於 \(u_{i,j}\) 和 \(d_{i,j}\) 的定義略有不同,寫的也是 \(O(nm^3)\) 的演算法。
程式碼如下(馬蜂很醜,不喜勿噴)——
#include<bits/stdc++.h>
#define N 505
#define LL long long
using namespace std;
int n,m,u[N][N],d[N][N],l[N][N],r[N][N];LL ans;
inline void solve(int x,int y){
for(register int i=y,u1=u[x][y],d1=d[x][y];i>=l[x][y];i--,u1=max(u1,u[x][i]),d1=min(d1,d[x][i]))
for(register int j=y,u2=u[x][y],d2=d[x][y];j<=r[x][y];j++,u2=max(u2,u[x][j]),d2=min(d2,d[x][j]))
ans-=1ll*(min(d1,d2)-x+1)*(x-max(u1,u2)+1);
for(register int i=y-1;i;i--) if(r[x][i]>=y) r[x][i]=y-1;else break;for(register int i=y+1;i<=m;i++) if(l[x][i]<=y) l[x][i]=y+1;else break;
for(register int i=x-1;i;i--) if(d[i][y]>=x) d[i][y]=x-1;else break;for(register int i=x+1;i<=n;i++) if(u[i][y]<=x) u[i][y]=x+1;else break;
}
inline int read(){int ret=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}while(isdigit(ch)) ret=(ret<<1)+(ret<<3)+ch-'0',ch=getchar();return ret*f;}
int main(){
n=read(),m=read(),ans=1ll*n*(n+1)/2ll*m*(m+1)/2ll;for(register int i=1;i<=n;i++) for(register int j=1;j<=m;j++) u[i][j]=1,d[i][j]=n,l[i][j]=1,r[i][j]=m;
for(register int i=1,x,y;i<=n*m;i++) x=read(),y=read(),solve(x,y),cout<<ans<<'\n';return 0;
}
T3:
Description:
有一個 \(2e9×2e9\) 的網格圖,第 \(x\) 行第 \(y\) 列的格子的座標為 \((x,y)\),也就是說左上角的格子的座標為 \((1,1)\),右下角的座標為 \((2e9,2e9)\)。
現在有個兄弟要從 \((x_1,y_1 )\) 走到 \((x_2,y_2)\),每次他只能走上下左右四個方向,這個兄弟永遠不能走到網格圖外面。
假設當前位置為 \((x,y)\),
向南走一步( \(x\) 加 \(1\))的代價為 \(2xy^2+2y^2+x^2\);
向北走一步( \(x\) 減 \(1\))的代價為 \(-2xy^2+2y^2+x^2\);
向東走一步( \(y\) 加 \(1\))的代價為 \(2x^2 y+2x^2+y^2\);
向西走一步( \(y\) 減 \(1\))的代價為 \(-2x^2 y+2x^2+y^2\);
請問從 \((x_1,y_1 )\) 走到 \((x_2,y_2 )\) 的最小代價是多少?
Input:
輸入第一行一個正整數 \(n\) 表示資料組數。 接下來 \(n\) 行,每行四個整數 \(x_1,y_1,x_2,y_2\)。
Output:
對於每組資料,一行一個整數表示答案。請輸出答案 mod \(998244353\)。
Sample1 Input:
4
1 1 1 1
1 3 2 1
2 1 1 3
10 2 20 6
Sample1 Output:
0
12
17
16999
Hint:
對於全部資料,\(1\leq n \leq 50000,1 \leq x1,y1,x2,y2 \leq 10^9\)
題目分析:
剛拿到這道題的時候說實話很難形成思路,但是我們可以先寫個DP打個表,然後我們能發現一些有趣的結論。
我們強制讓 \(x1\leq y1\) ,(可以通過交換 \(x1,y1\) 和 \(x2,y2\) 實現),於是可以大致分為4類:
1’.\(x1\leq x2\) 且 \(y1 \leq y2\) :
1‘’. \(x2 \leq y2\) 且 \(x2 \leq y1\) :我們採用 \(A->C->B\) 的行進路線:
2‘’. \(x2 \leq y2\) 且 \(x2 > y1\) :我們採用如下行進路線:
3‘’.\(x2>y2\):我們採用如下行進路線:
2‘.\(x1>x2\) 且 \(y1\le y2\):我們採用如下行進路線:
3’.\(x1\le x2\) 且 \(y1>y2\):我們採用如下行進路線:
4‘.\(x1>x2\) 且 \(y1>y2\):
1’‘.\(x2\leq y2\) 且 \(x1\leq y2\):我們採用如下行進路線:
2’‘.\(x2\leq y2\) 且 \(x1>y2\):我們採用如下行進路線:
3’‘.\(x2>y2\):我們採用如下行進路線:
知道路線怎麼走之後我們就能“輕鬆”地打出這道題,但是問題在於為什麼路線是這樣走的呢?
我們觀察代價的柿子就會發現,一條路徑 \((x_1,y_1)->(x_2,y_2)->……->(x_n,y_n)\) 的代價為 \(x_n^2y_n^2-x_1^2y_1^2+\sum_{i=1}^{n-1}{(x_i^2+y_i^2)}\)
由此看來,我們的代價只與 \(\sum_{i=1}^{n-1}{(x_i^2+y_i^2)}\) 有關,用貪心和基本不等式的思想稍微想一想就能粗略證明上述分類討論的正確性。
程式碼如下(馬蜂很醜,不喜勿噴)——
#include<bits/stdc++.h>
#define N 2000005
#define LL long long
using namespace std;
int T,inv;const int p=998244353;
inline int power(int x,int y){int z=1;while(y){if(y&1) z=1ll*z*x%p;y>>=1,x=1ll*x*x%p;}return z;}
inline int calc1(int x,int y){return (1ll*(x+y)*(y-x+1)/2ll)%p;}
inline int calc2(int x,int y){return (1ll*y*(y+1)%p*(2*y+1)%p*inv%p-1ll*(x-1)*x%p*(2*x-1)%p*inv%p+p)%p;}
inline int calc3(int x,int y){return (1ll*calc1(1,y)*calc1(1,y)%p-1ll*calc1(1,x-1)*calc1(1,x-1)%p+p)%p;}
inline int read(){int ret=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}while(isdigit(ch)) ret=(ret<<1)+(ret<<3)+ch-'0',ch=getchar();return ret*f;}
int main(){
inv=power(6,p-2),T=read();while(T--){
int sx=read(),sy=read(),tx=read(),ty=read();if(sx>sy) swap(sx,sy),swap(tx,ty);
if(sx<=tx&&sy<=ty){
if(tx<=ty){
if(sy>=tx){
LL res1=(2ll*calc1(sx,tx-1)*sy%p*sy%p+2ll*sy*sy%p*(tx-sx)%p+(LL)calc2(sx,tx-1))%p;
LL res2=(2ll*calc1(sy,ty-1)*tx%p*tx%p+2ll*tx*tx%p*(ty-sy)%p+(LL)calc2(sy,ty-1))%p;
LL ans=(res1+res2)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
else{
LL res1=(2ll*calc1(sx,sy-1)*sy%p*sy%p+2ll*sy*sy%p*(sy-sx)%p+(LL)calc2(sx,sy-1))%p;
LL res2=(2ll*calc3(sy,tx-1)+2ll*calc3(sy+1,tx)+4ll*calc2(sy,tx-1))%p;
LL res3=(2ll*calc1(tx,ty-1)*tx%p*tx%p+2ll*tx*tx%p*(ty-tx)%p+(LL)calc2(tx,ty-1))%p;
LL ans=(res1+res2+res3)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
}
else{
LL res1=(2ll*calc1(sx,sy-1)*sy%p*sy%p+2ll*sy*sy%p*(sy-sx)%p+(LL)calc2(sx,sy-1))%p;
LL res2=(2ll*calc3(sy,ty-1)+2ll*calc3(sy+1,ty)+4ll*calc2(sy,ty-1))%p;
LL res3=(2ll*calc1(ty,tx-1)*ty%p*ty%p+2ll*ty*ty%p*(tx-ty)%p+(LL)calc2(ty,tx-1))%p;
LL ans=(res1+res2+res3)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
}
if(sx>tx&&sy<=ty){
LL res1=(-2ll*calc1(tx+1,sx)*sy%p*sy%p+2ll*sy*sy%p*(sx-tx)%p+(LL)calc2(tx+1,sx))%p;
LL res2=(2ll*calc1(sy,ty-1)*tx%p*tx%p+2ll*tx*tx%p*(ty-sy)%p+(LL)calc2(sy,ty-1))%p;
LL ans=(res1+res2)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
if(sx<=tx&&sy>ty){
LL res1=(-2ll*calc1(ty+1,sy)*sx%p*sx%p+2ll*sx*sx%p*(sy-ty)%p+(LL)calc2(ty+1,sy))%p;
LL res2=(2ll*calc1(sx,tx-1)*ty%p*ty%p+2ll*ty*ty%p*(tx-sx)%p+(LL)calc2(sx,tx-1))%p;
LL ans=(res1+res2)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
if(sx>tx&&sy>ty){
if(tx<=ty){
if(ty>=sx){
LL res1=(-2ll*calc1(ty+1,sy)*sx%p*sx%p+2ll*sx*sx%p*(sy-ty)%p+(LL)calc2(ty+1,sy))%p;
LL res2=(-2ll*calc1(tx+1,sx)*ty%p*ty%p+2ll*ty*ty%p*(sx-tx)%p+(LL)calc2(tx+1,sx))%p;
LL ans=(res1+res2)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
else{
LL res1=(-2ll*calc1(sx+1,sy)*sx%p*sx%p+2ll*sx*sx%p*(sy-sx)%p+(LL)calc2(sx+1,sy))%p;
LL res2=(-2ll*calc3(ty+1,sx)-2ll*calc3(ty,sx-1)+4ll*calc2(ty+1,sx))%p;
LL res3=(-2ll*calc1(tx+1,ty)*ty%p*ty%p+2ll*ty*ty%p*(ty-tx)%p+(LL)calc2(tx+1,ty))%p;
LL ans=(res1+res2+res3)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
}
else{
LL res1=(-2ll*calc1(sx+1,sy)*sx%p*sx%p+2ll*sx*sx%p*(sy-sx)%p+(LL)calc2(sx+1,sy))%p;
LL res2=(-2ll*calc3(tx+1,sx)-2ll*calc3(tx,sx-1)+4ll*calc2(tx+1,sx))%p;
LL res3=(-2ll*calc1(ty+1,tx)*tx%p*tx%p+2ll*tx*tx%p*(tx-ty)%p+(LL)calc2(ty+1,tx))%p;
LL ans=(res1+res2+res3)%p;ans=(ans+p)%p;cout<<ans<<'\n';continue;
}
}
}
return 0;
}
//向南走一步(x+1)的代價為 2xy^2+2y^2+x^2;
//向北走一步(x-1)的代價為 -2xy^2+2y^2+x^2;
//向東走一步(y+1)的代價為 2x^2y+2x^2+y^2;
//向西走一步(y-1)的代價為 -2x^2y+2x^2+y^2;
T4:
Description:
今天是杜老師的生日,蝸蝸給杜老師買了個大蛋糕。蛋糕裡一共有 \(n\) 塊巧克力,巧克力的形狀都是長方體,第 \(i\) 塊巧克力包含了所有點 \((x,y,z)\) 滿足 \(minx[i]≤x≤maxx[i],miny[i]≤y≤maxy[i],minz[i]≤z≤maxz[i]\) 。巧克力之間可能會有重疊。
杜老師想在上面切三刀。第一刀必須切一個 \(x=a\) 的平面,第二刀必須切一個 \(y=b\) 的平面,第三刀必須切一個 \(z=c\) 的平面,其中 \(a,b,c\) 為 \(3\) 個整數。與此同時,需要滿足每一塊巧克力都至少被其中一刀切到(切到的定義是巧克力和至少一個平面的交非空)。
請幫杜老師切這 \(3\) 刀。
Input:
第一行一個整數 \(n\)。 接下來 \(n\) 行,每行 \(6\) 個整數 \(minx[i],maxx[i],miny[i],maxy[i],minz[i],maxz[i]\)。
Output:
如果無解,輸出NO。
否則第一行輸出YES,第二行輸出 \(3\) 個整數 \(a,b,c\)
如果存在多解,輸出任意一組即可。
Sample1 Input:
3
0 1 0 1 0 1
10 11 10 11 10 11
999999999 1000000000 999999999 1000000000 999999999 1000000000
Sample1 Output:
YES
0 10 999999999
Sample2 Input:
4
0 1 0 1 0 1
999999999 1000000000 0 1 0 1
0 1 999999999 1000000000 0 1
0 1 0 1 999999999 1000000000
Sample2 Output:
YES
0 0 0
Hint:
對於 \(100\%\) 的資料,滿足 \(1\le n\le 10^5\),\(-10^9\le minx[i],maxx[i],miny[i],maxy[i],minz[i],maxz[i]\le 10^9\),\(minx[i]<maxx[i],miny[i]<maxy[i],minz[i]<maxz[i]\)。
題目分析:
正解貌似是線段樹,但是碼量太大了,博主目前還沒有寫正解的打算(我太菜了
於是博主講一講博主的騙分方法。我們對於每一個 \(x=i\) 預處理出能切到的蛋糕數量。按照數量從大到小排序,然後用 \(nlogn\) 的複雜度對於每一個 \(x=i\) 判斷一遍,知道找出合法解。如果超過時間限制就直接退出輸出“NO”。根據實測可以拿到 \(80\) 分。
我們把時限分成三份,分別對 \(x,y,z\) 都做一遍。該方法通過實測可以拿到 \(90\) 分...
Hack 資料造起來不是很難,但是在考場上拿分還是能拿到可觀的分數,由此可見騙分的重要性。
80分程式碼如下(馬蜂很醜,不喜勿噴)——
#include<bits/stdc++.h>
#define N 100005
#define inf 1000000001
#define max(a,b) (a)>(b)?(a):(b)
#define s_id multiset<int>::iterator
using namespace std;
int n,m,tot,R[N],V[N],rk[N],lx[N],rx[N],ly[N],ry[N],lz[N],rz[N],p[N],S[N*6];multiset<int> T1,T2;vector<int> g;
struct node{int ly,ry,lz,rz;bool operator <(const node&x)const{return ry>x.ry;}};priority_queue<node> heap;
inline bool cmp(int x,int y){return ly[x]<ly[y];}
inline bool cmp2(int x,int y){return V[x]>V[y];}
inline int get(int x){return lower_bound(g.begin(),g.end(),x)-g.begin()+1;}
inline void U(int x,int y){for(register int i=x;i<=m;i+=i&-i) S[i]+=y;}
inline int Q(int x){int res=0;for(register int i=x;i;i-=i&-i) res+=S[i];return res;}
inline void solve(int X){
if(!tot){puts("YES");cout<<g[X-1]<<" 0 0"<<'\n';exit(0);} T1.clear(),T2.clear();for(register int i=1;i<=tot;i++) T1.insert(lz[p[i]]),T2.insert(rz[p[i]]);
s_id it=T1.end();it--;int maxz=*it,minz=*T2.begin();if(minz>=maxz){puts("YES");cout<<g[X-1]<<" 0 "<<g[maxz-1]<<'\n';exit(0);}
while(!heap.empty()) heap.pop();for(register int i=1;i<=tot;i++){
int Y=ly[p[i]];while(!heap.empty()){node tmp=heap.top();if(tmp.ry<Y) heap.pop(),T1.insert(tmp.lz),T2.insert(tmp.rz);else break;}
it=T1.lower_bound(lz[p[i]]);T1.erase(it);it=T2.lower_bound(rz[p[i]]);T2.erase(it);heap.push(node{ly[p[i]],ry[p[i]],lz[p[i]],rz[p[i]]});
if(T1.empty()){puts("YES");cout<<g[X-1]<<' '<<g[Y-1]<<" 0"<<'\n';exit(0);}it=T1.end();it--,maxz=*it,minz=*T2.begin();
if(minz>=maxz){puts("YES");cout<<g[X-1]<<' '<<g[Y-1]<<' '<<g[maxz-1]<<'\n';exit(0);}
}
}
inline int read(){int ret=0,f=1;char ch=getchar();while(!isdigit(ch)){if(ch=='-') f=-f;ch=getchar();}while(isdigit(ch)) ret=(ret<<1)+(ret<<3)+ch-'0',ch=getchar();return ret*f;}
int main(){
n=read();for(register int i=1;i<=n;i++) R[i]=i,lx[i]=read(),rx[i]=read(),ly[i]=read(),ry[i]=read(),lz[i]=read(),rz[i]=read(),rk[i]=i,
g.push_back(lx[i]),g.push_back(rx[i]),g.push_back(ly[i]),g.push_back(ry[i]),g.push_back(lz[i]),g.push_back(rz[i]);
sort(g.begin(),g.end()),g.erase(unique(g.begin(),g.end()),g.end()),sort(rk+1,rk+n+1,cmp),m=g.size();for(register int i=1;i<=n;i++)
lx[i]=get(lx[i]),ly[i]=get(ly[i]),lz[i]=get(lz[i]),rx[i]=get(rx[i]),ry[i]=get(ry[i]),rz[i]=get(rz[i]),U(lx[i],1),U(rx[i]+1,-1);for(register int i=1;i<=n;i++) V[i]=Q(lx[i]);sort(R+1,R+n+1,cmp2);
for(register int i=1;i<=n;i++){if((double)clock()/CLOCKS_PER_SEC>2.5){break;}int X=lx[R[i]];tot=0;for(register int j=1;j<=n;j++) if(lx[rk[j]]>X||X>rx[rk[j]]) p[++tot]=rk[j];solve(X);}puts("NO");return 0;
}