求卡常或提供特殊数据做法
查看原帖
求卡常或提供特殊数据做法
342076
Union_of_Britainschanghang楼主2023/11/23 21:45

只有 o=1o=1 的数据会使我 TLE(被卡常似乎也是都在这一块),求特殊做法或卡常:

// Problem: P9061 [Ynoi2002] Optimal Ordered Problem Solver
// Platform: Luogu
// URL: https://www.luogu.com.cn/problem/P9061
// Memory Limit: 512 MB
// Time Limit: 4000 ms
// Author:British Union
// Long live UOB and koala
// 
// Powered by CP Editor (https://cpeditor.org)

#include<bits/stdc++.h>
using namespace std;
// #define int long long
namespace FastIO {
#if __cplusplus < 201400
#error Please use C++14 or higher.
#endif
#if __cplusplus > 201700
#define INLINE_V inline
#else
#define INLINE_V
#endif
#if (defined(LOCAL) || defined(_WIN32)) && !defined(DISABLE_MMAP)
#define DISABLE_MMAP
#endif
#ifndef DISABLE_MMAP
#include <sys/mman.h>
#endif
#ifdef LOCAL
inline char gc() { return getchar(); }
inline void pc(char c) { putchar(c); }
#else
#ifdef DISABLE_MMAP
INLINE_V constexpr int _READ_SIZE = 1 << 18;
INLINE_V static char _read_buffer[_READ_SIZE], *_read_ptr = nullptr,
                                               *_read_ptr_end = nullptr;
inline char gc() {
    if (__builtin_expect(_read_ptr == _read_ptr_end, false)) {
        _read_ptr = _read_buffer;
        _read_ptr_end =
            _read_buffer + fread(_read_buffer, 1, _READ_SIZE, stdin);
#ifdef CHK_EOF
        if (__builtin_expect(_read_ptr == _read_ptr_end, false)) return EOF;
#endif
    }
    return *_read_ptr++;
}
#else
INLINE_V static const char *_read_ptr =
    (const char *)mmap(nullptr, INT_MAX, 1, 2, 0, 0);
inline char gc() { return *_read_ptr++; }
#endif
INLINE_V constexpr int _WRITE_SIZE = 1 << 18;
INLINE_V static char _write_buffer[_WRITE_SIZE], *_write_ptr = _write_buffer;
inline void pc(char c) {
    *_write_ptr++ = c;
    if (__builtin_expect(_write_buffer + _WRITE_SIZE == _write_ptr, false)) {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
        _write_ptr = _write_buffer;
    }
}
INLINE_V struct _auto_flush {
    ~_auto_flush() {
        fwrite(_write_buffer, 1, _write_ptr - _write_buffer, stdout);
    }
} _auto_flush;
#endif
#ifdef CHK_EOF
inline bool _isdigit(char c) { return (c & 16) && c != EOF; }
inline bool _isgraph(char c) { return c > 32 && c != EOF; }
#else
inline bool _isdigit(char c) { return c & 16; }
inline bool _isgraph(char c) { return c > 32; }
#endif
template <class T>
INLINE_V constexpr bool _is_integer = numeric_limits<T>::is_integer;
template <class T>
INLINE_V constexpr bool _is_signed = numeric_limits<T>::is_signed;
template <class T>
INLINE_V constexpr bool _is_unsigned = _is_integer<T> && !_is_signed<T>;
template <>
INLINE_V constexpr bool _is_integer<__int128> = true;
template <>
INLINE_V constexpr bool _is_integer<__uint128_t> = true;
template <>
INLINE_V constexpr bool _is_signed<__int128> = true;
template <>
INLINE_V constexpr bool _is_unsigned<__uint128_t> = true;
#undef INLINE_V
inline void read(char &c) {
    do c = gc();
    while (!_isgraph(c));
}
inline void read_cstr(char *s) {
    char c = gc();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) *s++ = c, c = gc();
    *s = 0;
}
inline void read(string &s) {
    char c = gc();
    s.clear();
    while (!_isgraph(c)) c = gc();
    while (_isgraph(c)) s.push_back(c), c = gc();
}
#ifdef IN_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void read(T &x) {
    char c = gc();
    bool f = true;
    x = 0;
    while (!_isdigit(c)) {
        if (c == 45) f = false;
        c = gc();
    }
    if (f)
        while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
    else
        while (_isdigit(c)) x = x * 10 - (c & 15), c = gc();
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void read(T &x) {
    char c = gc();
    while (!_isdigit(c)) c = gc();
    x = 0;
    while (_isdigit(c)) x = x * 10 + (c & 15), c = gc();
}
inline void write(char c) { pc(c); }
inline void write_cstr(const char *s) {
    while (*s) pc(*s++);
}
inline void write(const string &s) {
    for (char c : s) pc(c);
}
#ifdef OUT_HAS_NEG
template <class T, enable_if_t<_is_signed<T>, int> = 0>
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    if (x >= 0) do
            buffer[digits++] = (x % 10) | 48, x /= 10;
        while (x);
    else {
        pc(45);
        do buffer[digits++] = -(x % 10) | 48, x /= 10;
        while (x);
    }
    while (digits) pc(buffer[--digits]);
}
template <class T, enable_if_t<_is_unsigned<T>, int> = 0>
#else
template <class T, enable_if_t<_is_integer<T>, int> = 0>
#endif
inline void write(T x) {
    char buffer[numeric_limits<T>::digits10 + 1];
    int digits = 0;
    do buffer[digits++] = (x % 10) | 48, x /= 10;
    while (x);
    while (digits) pc(buffer[--digits]);
}
template <int N>
struct _tuple_io_helper {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_read(x), read(get<N - 1>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        _tuple_io_helper<N - 1>::_write(x), pc(32), write(get<N - 1>(x));
    }
};
template <>
struct _tuple_io_helper<1> {
    template <class... T>
    static inline void _read(tuple<T...> &x) {
        read(get<0>(x));
    }
    template <class... T>
    static inline void _write(const tuple<T...> &x) {
        write(get<0>(x));
    }
};
template <class... T>
inline void read(tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_read(x);
}
template <class... T>
inline void write(const tuple<T...> &x) {
    _tuple_io_helper<sizeof...(T)>::_write(x);
}
template <class T1, class T2>
inline void read(pair<T1, T2> &x) {
    read(x.first), read(x.second);
}
template <class T1, class T2>
inline void write(const pair<T1, T2> &x) {
    write(x.first), pc(32), write(x.second);
}
template <class T1, class... T2>
inline void read(T1 &x, T2 &...y) {
    read(x), read(y...);
}
template <class... T>
inline void read_cstr(char *x, T *...y) {
    read_cstr(x), read_cstr(y...);
}
template <class T1, class... T2>
inline void write(const T1 &x, const T2 &...y) {
    write(x), write(y...);
}
template <class... T>
inline void write_cstr(const char *x, const T *...y) {
    write_cstr(x), write_cstr(y...);
}
template <class T>
inline void print(const T &x) {
    write(x);
}
inline void print_cstr(const char *x) { write_cstr(x); }
template <class T1, class... T2>
inline void print(const T1 &x, const T2 &...y) {
    print(x), pc(32), print(y...);
}
template <class... T>
inline void print_cstr(const char *x, const T *...y) {
    print_cstr(x), pc(32), print_cstr(y...);
}
inline void println() { pc(10); }
inline void println_cstr() { pc(10); }
template <class... T>
inline void println(const T &...x) {
    print(x...), pc(10);
}
template <class... T>
inline void println_cstr(const T *...x) {
    print_cstr(x...), pc(10);
}
}
using namespace FastIO;
const int maxn=1e6+5;
int n;
struct BIT{
	int c[maxn];
	BIT(){memset(c,0,sizeof(c));}
	inline void add(int p,int x){
		for(;p<=n;p+=p&-p)c[p]+=x;
	}
	inline int query(int p){
		int res=0;
		for(;p;p-=p&-p)res+=c[p];
		return res;
	}
	inline int ask(int l,int r){
		return query(r)-query(l-1);
	}
}B,Bt1,Bt2;
struct BIT2{
	int c[maxn];
	BIT2(){memset(c,0x3f3f3f3f,sizeof(c));}
	inline void add(int p,int x){
		p=n-p+1;
		for(;p<=n;p+=p&-p)c[p]=min(c[p],x);
	}
	inline int query(int p){
		int res=0x3f3f3f3f;p=n-p+1;
		for(;p;p-=p&-p)res=min(res,c[p]);
		return res;
	}
}B2;
struct BIT3{
	int c[maxn];
	BIT3(){memset(c,0,sizeof(c));}
	inline void add(int p,int x){
		p=n-p+1;
		for(;p<=n;p+=p&-p)c[p]=max(c[p],x);
	}
	inline int query(int p){
		int res=0;p=n-p+1;
		for(;p;p-=p&-p)res=max(res,c[p]);
		return res;
	}
}B3;
struct pt{
	int x,y;
	pt(int a=0,int b=0){x=a,y=b;}
	inline bool operator <(const pt &b)const{return x==b.x?y>b.y:x<b.x;}
	inline bool operator ==(const pt &b)const{return x==b.x&&y==b.y;}
};
inline bool operator <=(const pt &a,const pt &b){return a<b||a==b;}
struct BST{
	int pri[maxn],l[maxn],r[maxn],sze[maxn];
	int tg1[maxn],tg2[maxn];
	pt val[maxn];
	int x,y,z,rt,cnt;
	BST(){
		cnt=0;
		memset(tg1,-1,sizeof(tg1));
		memset(tg2,-1,sizeof(tg2));
	}
	inline void pushup(int x){
		sze[x]=sze[l[x]]+sze[r[x]]+1;
	}
	inline void opr(int k,int tp,int v){
		if(!k)return ;
		if(tp==1){
			val[k].y=v;
			tg1[k]=v;
		}else{
			val[k].x=v;
			tg2[k]=v;
		}
	}
	inline void pushdown(int k){
		if(tg1[k]!=-1){
			opr(l[k],1,tg1[k]);
			opr(r[k],1,tg1[k]);
			tg1[k]=-1;
		}
		if(tg2[k]!=-1){
			opr(l[k],2,tg2[k]);
			opr(r[k],2,tg2[k]);
			tg2[k]=-1;
		}
	}
	void split(int now,pt k,int &x,int &y){
		if(!now)x=y=0;
		else{
			pushdown(now);
			if(val[now]<=k)x=now,split(r[now],k,r[now],y);
			else y=now,split(l[now],k,x,l[now]);
			pushup(now);
		}
	}
	void splitx(int now,int k,int &x,int &y){
		if(!now)x=y=0;
		else{
			pushdown(now);
			if(val[now].x<=k)x=now,splitx(r[now],k,r[now],y);
			else y=now,splitx(l[now],k,x,l[now]);
			pushup(now);
		}
	}
	void splity(int now,int k,int &x,int &y){
		// cout<<now<<" "<<k<<" "<<l[now]<<" "<<r[now]<<endl;
		if(!now)x=y=0;
		else{
			// cout<<"Oh fuck"<<endl;
			pushdown(now);
			if(val[now].y>k)x=now,splity(r[now],k,r[now],y);
			else y=now,splity(l[now],k,x,l[now]);
			pushup(now);
		}
	}
	int merge(int x,int y){
		if(!x||!y)return x+y;
		if(pri[x]<pri[y]){
			pushdown(x);
			r[x]=merge(r[x],y);
			pushup(x);
			return x;
		}else{
			pushdown(y);
			l[y]=merge(x,l[y]);
			pushup(y);
			return y;
		}
	}
	inline int newnode(pt v){
		val[++cnt]=v,sze[cnt]=1,pri[cnt]=rand();
		return cnt;
	}
	inline void ins(pt v){
		split(rt,v,x,y);
		rt=merge(x,merge(newnode(v),y));
	}
}F;
int m;
pair<int,int> a[maxn];
int per[maxn];
int o[maxn],xi[maxn],yi[maxn],Xi[maxn],Yi[maxn],ans[maxn];
int Int[maxn];
inline bool cmp(int x,int y){
	return Xi[x]<Xi[y];
}
inline bool cmp2(int x,int y){
	return xi[x]<xi[y];
}
vector<int> e[maxn];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	read(n,m);
	for(int i=1;i<=n;i++){
		read(a[i].first,a[i].second);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=m;i++){
		read(o[i],xi[i],yi[i],Xi[i],Yi[i]);
		per[i]=i;
	}
	sort(per+1,per+m+1,cmp);
	int now=n;
	for(int i=m;i>=1;i--){
		while(now>=1&&a[now].first>Xi[per[i]]){
			B.add(a[now].second,1);
			--now;
		}
		ans[per[i]]=B.ask(Yi[per[i]]+1,n);
	}
	now=m;
	sort(per+1,per+m+1,cmp2);
	for(int i=n;i>=1;i--){
		while(now>=1&&xi[per[now]]>=a[i].first){
			B2.add(yi[per[now]],per[now]);
			--now;
		}
		Int[i]=B2.query(a[i].second);
		if(Int[i]!=0x3f3f3f3f)e[Int[i]].push_back(i);
	}
	for(int i=1;i<=n;i++)Bt1.add(a[i].first,1),Bt2.add(a[i].second,1);
	int ct=0;
	for(int i=1;i<=m;i++){
		F.splitx(F.rt,xi[i],F.x,F.y);
		int P=F.y;
		F.splity(F.x,yi[i],F.z,F.y);
		if(F.y)F.opr(F.y,o[i],o[i]==1?yi[i]:xi[i]);
		F.rt=F.merge(F.merge(F.z,F.y),P);
		for(auto u:e[i]){
			Bt1.add(a[u].first,-1);
			Bt2.add(a[u].second,-1);
			if(o[i]==1)a[u].second=yi[i];
			else a[u].first=xi[i];
			ct++;
			F.ins(pt(a[u].first,a[u].second));
		}
		B3.add(xi[i],yi[i]);
		if(B3.query(Xi[i]+1)>Yi[i]){
			println(0);
		}else{
			ans[i]+=Bt1.query(Xi[i]);
			ans[i]+=Bt2.query(Yi[i]);
			F.splity(F.rt,Yi[i],F.x,F.y);
			F.splitx(F.y,Xi[i],F.y,F.z);
			ans[i]+=F.sze[F.y]*2;
			ans[i]-=(n-(ct-F.sze[F.y]));
			F.rt=F.merge(F.x,F.merge(F.y,F.z));
			println(ans[i]);
		}
	}
	
	return 0;
}
2023/11/23 21:45
加载中...