QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#322253#7436. Optimal Ordered Problem SolverWinResearcherCompile Error//C++144.1kb2024-02-06 17:02:372024-02-06 17:02:39

Judging History

你现在查看的是最新测评结果

  • [2024-02-06 17:02:39]
  • 评测
  • [2024-02-06 17:02:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REPG(i,h,x) for(int i=h[x];~i;i=edge[i].next)
#define CLR(a,x) memset(a,x,sizeof(a))
#define pii pair<int,int>
const int INF=0x3f3f3f3f;

const int N=1e6+5;
int n,q,P[N],ans[N];
pii a[N];
vector<int> vec[N];
struct ask{int op,x,y,X,Y;}Q[N];
namespace FHQ{
	int root,cnt;
	mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());
	struct node{int lc,rc,x,y,xlazy,ylazy,siz;unsigned key;}t[N];
	inline int& lc(int p){return t[p].lc;}
	inline int& rc(int p){return t[p].rc;}
	inline void newnode(int id){t[id]={0,0,a[id].first,a[id].second,-1,-1,1,rnd()};}
	inline void pushup(int p){t[p].siz=t[lc(p)].siz+t[rc(p)].siz+1;}
	inline void pushX(int p,int v){t[p].x=t[p].xlazy=v;}
	inline void pushY(int p,int v){t[p].y=t[p].ylazy=v;}
	inline void pushdown(int p){
		if(t[p].xlazy!=-1) pushX(lc(p),t[p].xlazy),pushX(rc(p),t[p].xlazy);
		if(t[p].ylazy!=-1) pushY(lc(p),t[p].ylazy),pushY(rc(p),t[p].ylazy);
		t[p].xlazy=t[p].ylazy=-1;
	}
	void splitX(int p,int v,int &l,int &r){
		if(!p) return (void)(l=r=0);
		pushdown(p);
		if(t[p].x<=v) splitX(rc(l=p),v,rc(p),r);
		else splitX(lc(r=p),v,l,lc(p));
		pushup(p);
	}	
	void splitY(int p,int v,int &l,int &r){
		if(!p) return (void)(l=r=0);
		pushdown(p);
		if(t[p].y>=v) splitY(rc(l=p),v,rc(p),r);
		else splitY(lc(r=p),v,l,lc(p));
		pushup(p);
	}
	int merge(int l,int r){
		if(!l||!r) return l|r;
		if(t[l].key<t[r].key){
			pushdown(l),rc(l)=merge(rc(l),r);
			return pushup(l),l;
		}
		else{
			pushdown(r),lc(r)=merge(l,lc(r));
			return pushup(r),r;
		}
	}
	inline void add(int id){
		newnode(id);
		int l,mid,r;
		splitX(root,a[id].first,l,r),splitY(l,a[id].second,l,mid);
		root=merge(merge(l,id),merge(mid,r));
	}
};
inline int lowbit(int x){return x&(-x);}
struct BIT{
	int bit[N];
	inline void add(int x,int v){for(;x<=n;x+=lowbit(x)) bit[x]+=v;}
	inline int ask(int x){int ans=0;for(;x;x-=lowbit(x)) ans+=bit[x];return ans;}
}bit1,bit2;
struct BIT2{
	int bit[N];
	BIT2(){CLR(bit,0x3f);}
	inline void add(int x,int v){for(;x;x-=lowbit(x)) bit[x]=min(bit[x],v);}
	inline int ask(int x){int ans=INF;for(;x<=n;x+=lowbit(x)) ans=min(ans,bit[x]);return ans;}
}bitmn;
struct BIT3{
	int bit[N];
	inline void add(int x,int v){for(;x;x-=lowbit(x)) bit[x]=max(bit[x],v);}
	inline int ask(int x){int ans=0;for(;x<=n;x+=lowbit(x)) ans=max(ans,bit[x]);return ans;}
}bitmx;
int main(){
//	ios::sync_with_stdio(false);
//	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%d%d",&n,&q);
	for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&a[i].second);
	for(int i=1;i<=q;i++) scanf("%d%d%d%d%d",&Q[i].op,&Q[i].x,&Q[i].y,&Q[i].X,&Q[i].Y),P[i]=i;
	sort(a+1,a+1+n),sort(P+1,P+1+q,[](int a,int b){return Q[a].x>Q[b].x;});
	for(int i=n,j=1;i>=1;i--){
		for(;j<=n&&Q[P[j]].x>=a[i].first;j++) bitmn.add(Q[P[j]].y,P[j]);
		int ret=bitmn.ask(a[i].second);
		if(ret!=INF) vec[ret].push_back(i);
	}
	sort(P+1,P+1+q,[](int a,int b){return Q[a].X>Q[b].X;});
	for(int i=1,j=n;i<=q;i++){
		for(;j>=1&&a[j].first>Q[P[i]].X;j--) bit1.add(a[j].second,1);
		ans[P[i]]=n-j-bit1.ask(Q[P[i]].Y);
	}
	CLR(bit1.bit,0);
	for(int i=1;i<=n;i++) bit1.add(a[i].first,1),bit2.add(a[i].second,1);
	for(int i=1;i<=q;i++){
		if(bitmx.ask(Q[i].x+1)<=Q[i].y){
			int l,mid,r;
			FHQ::splitX(FHQ::root,Q[i].x,l,r);
			FHQ::splitY(l,Q[i].y+1,l,mid)
			if(mid){
				if(Q[i].op==1) FHQ::pushY(mid,Q[i].y);
				else FHQ::pushX(mid,Q[i].x);
			}
			FHQ::root=FHQ::merge(FHQ::merge(l,mid),r);
			bitmx.add(Q[i].x,Q[i].y);
		}
		for(auto j:vec[i]){
			bit1.add(a[j].first,-1),bit2.add(a[j].second,-1);
			if(Q[i].op==1) a[j].second=Q[i].y;
			else a[j].first=Q[i].x;
			FHQ::add(j);
		}
		if(bitmx.ask(Q[i].X+1)>Q[i].Y) ans[i]=0;
		else{
			int l,mid,r;
			ans[i]+=bit1.ask(Q[i].X)+bit2.ask(Q[i].Y)+FHQ::t[FHQ::root].siz;
			FHQ::splitX(FHQ::root,Q[i].X,l,r);
			FHQ::splitY(l,Q[i].Y+1,l,mid);
			ans[i]+=FHQ::t[mid].siz-n;
			FHQ::root=FHQ::merge(FHQ::merge(l,mid),r);	
		}
		printf("%d\n",ans[i]);
	}	
	return 0;
}

詳細信息

answer.code: In function ‘void FHQ::newnode(int)’:
answer.code:20:84: warning: narrowing conversion of ‘FHQ::rnd.std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::operator()()’ from ‘std::mersenne_twister_engine<long unsigned int, 32, 624, 397, 31, 2567483615, 11, 4294967295, 7, 2636928640, 15, 4022730752, 18, 1812433253>::result_type’ {aka ‘long unsigned int’} to ‘unsigned int’ [-Wnarrowing]
   20 |         inline void newnode(int id){t[id]={0,0,a[id].first,a[id].second,-1,-1,1,rnd()};}
      |                                                                                 ~~~^~
answer.code: In function ‘int main()’:
answer.code:103:54: error: expected ‘;’ before ‘if’
  103 |                         FHQ::splitY(l,Q[i].y+1,l,mid)
      |                                                      ^
      |                                                      ;
  104 |                         if(mid){
      |                         ~~                            
answer.code:83:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   83 |         scanf("%d%d",&n,&q);
      |         ~~~~~^~~~~~~~~~~~~~
answer.code:84:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   84 |         for(int i=1;i<=n;i++) scanf("%d%d",&a[i].first,&a[i].second);
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
answer.code:85:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   85 |         for(int i=1;i<=q;i++) scanf("%d%d%d%d%d",&Q[i].op,&Q[i].x,&Q[i].y,&Q[i].X,&Q[i].Y),P[i]=i;
      |                               ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~