跳到正文

2147483647str

679800

于无声处听惊雷

在洛谷打开
资料、奖项与版本

资料

编号
679800
抓取

奖项

2026 NOI
金牌
C++
namespace Fread {
	const int SIZE=1<<21;char buf[SIZE],*S,*T;
	inline char getchar() {if(S==T){T=(S=buf)+fread(buf,1,SIZE,stdin);if(S==T)return '\n';}return *S++;}
}
namespace Fwrite {
	const int SIZE=1<<21;
	char buf[SIZE],*S=buf,*T=buf+SIZE;
	inline void flush(){fwrite(buf,1,S-buf,stdout);S=buf;}
	inline void putchar(char c){*S++=c;if(S==T)flush();}
	struct POPOSSIBLE{~POPOSSIBLE(){flush();}}ztr;
}
#define getchar Fread :: getchar
#define putchar Fwrite :: putchar
namespace Fastio{
	struct Reader{
	    template<typename T>
    	Reader& operator >> (T& x) {
        	char c=getchar();T f=1;
        	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}x=0;
        	while(c>='0'&&c<='9'){x=x*10+(c-'0');c=getchar();}x*=f;
	        return *this;
    	}
	    Reader(){}
	}cin;
	struct Writer{
	    template<typename T>
	    Writer& operator << (T x) {
	        if(x==0){putchar('0');return *this;}
	        if(x<0){putchar('-');x=-x;}
	        static int sta[45];int top=0;
	        while(x){sta[++top]=x%10;x/=10;}
	        while(top){putchar(sta[top]+'0');--top;}
	        return *this;
    	}
    	Writer& operator << (char c) {putchar(c);return *this;}
    	Writer(){}
	}cout;
}
#define endl '\n'
#define cin Fastio :: cin
#define cout Fastio :: cout
C++
#include<bits/stdc++.h>
using namespace std;
const int N=3e3+5,mod=998244353,G=3,Gi=(mod+1)/3;
inline void chk(int&x,int y){(x+=y)>=mod&&(x-=mod);}
int jie[N],inv[N];
int qpow(int a,int b){
    int res=1;
    while(b){
        if(b&1)res=1ll*a*res%mod;
        b>>=1;a=1ll*a*a%mod;
    }return res;
}
int C(int n,int m){return 1ll*jie[n]*inv[m]%mod*inv[n-m]%mod;}
int dp[N][N],ct1,ct2;
typedef vector<int>poly;
int r[N<<1];
void init(int n){
    for(int i=0;i<n;i++)r[i]=(r[i>>1]>>1)|((i&1)*(n>>1));
}
void NTT(poly&a,int n,int op){
    for(int i=0;i<n;i++)if(i<r[i])swap(a[i],a[r[i]]);
    for(int mid=1;mid<n;mid<<=1){
        int wn=qpow((op==1)?G:Gi,(mod-1)/(mid<<1));
        for(int j=0;j<n;j+=(mid<<1)){
            int w=1;
            for(int k=0;k<mid;k++,w=1ll*w*wn%mod){
                int x=a[j+k],y=1ll*w*a[j+k+mid]%mod;
                a[j+k]=(x+y)%mod;
                a[j+k+mid]=(x+mod-y)%mod;
            }
        }
    }
    if(op==-1){
        int qwq=qpow(n,mod-2);
        for(int i=0;i<n;i++)a[i]=1ll*a[i]*qwq%mod;
    }
}
poly operator*(poly f,poly g){
    int n=f.size(),m=g.size();
    int lim=1;while(lim<n+m+1)lim<<=1;
    f.resize(lim),g.resize(lim);init(lim);
    NTT(f,lim,1);NTT(g,lim,1);
    for(int i=0;i<lim;i++)f[i]=1ll*f[i]*g[i]%mod;
    NTT(f,lim,-1);f.resize(n+m-1);return f;
}
C++
Matrix operator+(Matrix a,Matrix b){
    Matrix res;
    res[0][0]=(a[0][0]+b[0][0])%mod;
    res[0][1]=(a[0][1]+b[0][1])%mod;
    res[1][0]=(a[1][0]+b[1][0])%mod;
    res[1][1]=(a[1][1]+b[1][1])%mod;
    return res;
}
Matrix operator*(Matrix a,Matrix b){
    Matrix res;
    res[0][0]=(1ll*a[0][0]*b[0][0]+1ll*a[0][1]*b[1][0])%mod;
    res[0][1]=(1ll*a[0][0]*b[0][1]+1ll*a[0][1]*b[1][1])%mod;
    res[1][0]=(1ll*a[1][0]*b[0][0]+1ll*a[1][1]*b[1][0])%mod;
    res[1][1]=(1ll*a[1][0]*b[0][1]+1ll*a[1][1]*b[1][1])%mod;
    return res;
}
C++
int mod;
inline unsigned int down(unsigned int x) {
	return x >= mod ? x - mod : x;
}
struct FastMod { // 请将该结构体直接复制,粘贴到你的代码中
    unsigned long long b, m;
    FastMod() = default;
    FastMod(unsigned long long m) : b(((unsigned __int128)1 << 64) / m), m(m) {}
    unsigned long long operator()(unsigned long long a) {
        unsigned long long q = (unsigned __int128)a * b >> 64;
        unsigned long long r = a - q * m;
        return r >= m ? r - m : r;
    }
} fastmod;
struct Modint {
	unsigned int x;
	Modint() = default;
	Modint(unsigned int x) : x(x) {}
	friend istream& operator>>(istream& in, Modint& a) {return in >> a.x;}
	friend ostream& operator<<(ostream& out, Modint a) {return out << a.x;}
	friend Modint operator+(Modint a, Modint b) {return down(a.x + b.x);}
	friend Modint operator-(Modint a, Modint b) {return down(a.x - b.x + mod);}
	friend Modint operator*(Modint a, Modint b) {return fastmod(1ULL * a.x * b.x);}
	friend Modint operator/(Modint a, Modint b) {return a * ~b;}
	friend Modint operator^(Modint a, int b) {Modint ans = 1; for(; b; b >>= 1, a *= a) if(b & 1) ans *= a; return ans;}
	friend Modint operator~(Modint a) {return a ^ (mod - 2);}
	friend Modint operator-(Modint a) {return down(mod - a.x);}
	friend Modint& operator+=(Modint& a, Modint b) {return a = a + b;}
	friend Modint& operator-=(Modint& a, Modint b) {return a = a - b;}
	friend Modint& operator*=(Modint& a, Modint b) {return a = a * b;}
	friend Modint& operator/=(Modint& a, Modint b) {return a = a / b;}
	friend Modint& operator^=(Modint& a, int b) {return a = a ^ b;}
	friend Modint& operator++(Modint& a) {return a += 1;}
	friend Modint operator++(Modint& a, int) {Modint x = a; a += 1; return x;}
	friend Modint& operator--(Modint& a) {return a -= 1;}
	friend Modint operator--(Modint& a, int) {Modint x = a; a -= 1; return x;}
	friend bool operator==(Modint a, Modint b) {return a.x == b.x;}
	friend bool operator!=(Modint a, Modint b) {return !(a == b);}
};
typedef Modint mint;
//使用前需要调用 fastmod = FastMod(mod);
C++
struct mint
{
	int s1, s2;
	mint operator+(const mint&x) const {return {s1+x.s1>=mo1?s1+x.s1-mo1:s1+x.s1, s2+x.s2>=mo2?s2+x.s2-mo2:s2+x.s2};}
	mint operator-(const mint&x) const {return {s1>=x.s1?s1-x.s1:s1+mo1-x.s1, s2>=x.s2?s2-x.s2:s2+mo2-x.s2};}
	mint operator*(const mint&x) const {return {(int)(1ll*s1*x.s1%mo1), (int)(1ll*s2*x.s2%mo2)};}
	bool operator==(const mint&x) const {return s1==x.s1&&s2==x.s2;}
}p2[M],s[N];
struct hmap{
	mint s[N];
	int cnt,h[M],p[N],nxt[N];
	#define val(x) (1ll*x.s1*mo2+x.s2)%M
	void ins(mint x,int k){
		int i=++cnt,a=val(x);
		s[i]=x,p[i]=k,nxt[i]=h[a],h[a]=i;
	}
	int ask(mint x){
		for(int i=h[val(x)];i; i=nxt[i])if(s[i]==x)return p[i];
		return -1;
	}
}mp;
C++
typedef unsigned long long ull;
struct Bitset{
    ull a[M];
    void reset(){
        memset(a,0,sizeof(a));
    }
    void set(int x){
        a[x>>6]|=1ull<<(x&63);
    }
    void flip(int x){
        a[x>>6]^=1ull<<(x&63);
    }
    void operator|=(const Bitset& b){
        for(int i=0;i<M;i++){
            a[i]|=b.a[i];
        }
    }
    void operator^=(const Bitset& b){
        for(int i=0;i<M;i++){
            a[i]^=b.a[i];
        }
    }
    void operator&=(const Bitset& b){
        for(int i=0;i<M;i++){
            a[i]&=b.a[i];
        }
    }
    bool operator[](int x)const{
        return a[x>>6]&(1ull<<(x&63));
    }
};
C++
typedef unsigned long long u64;
typedef unsigned __int128 u128;
typedef long long i64;
typedef __int128 i128;
void write(u128 x){
    if(x>9)write(x/10);
    putchar(x%10+'0');
}
int n,m,q;
struct i256{
    i128 x;
    u128 y;
    i256(i128 x=0,u128 y=0):x(x),y(y){}
    i256(int u){
        if(u>=0)x=0,y=u;
        else x=-1,y=u;
    }
};
i256 operator+(i256 a,i256 b){
    i256 c;
    c.y=a.y+b.y;
    c.x=a.x+b.x;
    if(c.y<a.y)c.x++;
    return c;
}
i256 operator-(i256 a,i256 b){
    i256 c;
    c.y=a.y-b.y;
    c.x=a.x-b.x;
    if(c.y>a.y)c.x--;
    return c;
}
i256 operator*(i256 a,i256 b){
    u64 a0=a.y&(u64)-1,a1=a.y>>64,a2=a.x&(u64)-1,a3=a.x>>64;
    u64 b0=b.y&(u64)-1,b1=b.y>>64,b2=b.x&(u64)-1,b3=b.x>>64;
    u128 c0=0,c1=0,c2=0,c3=0;
    c0=a0*b0;c1+=(u128)a0*b0>>64;
    c1+=(u128)0+a0*b1+a1*b0;c2+=((u128)a0*b1>>64)+((u128)a1*b0>>64);
    c2+=(u128)0+a0*b2+a1*b1+a2*b0;c3+=((u128)a0*b2>>64)+((u128)a1*b1>>64)+((u128)a2*b0>>64);
    c3+=(u128)0+a0*b3+a1*b2+a2*b1+a3*b0;
    c1+=c0>>64;c0&=(u64)-1;
    c2+=c1>>64;c1&=(u64)-1;
    c3+=c2>>64;c2&=(u64)-1;
    return {c3<<64|c2,c1<<64|c0};
}
i256 operator<<(i256 a,int b){
    if(!b)return a;
    if(b<128)return{a.x<<b|a.y>>(128-b),a.y<<b};
    return{a.y<<b-128,0};
}
i256 operator>>(i256 a,int b){
    if(!b)return a;
    if(b<128)return{a.x>>b,a.y>>b|(a.x<<(128-b))};
    return{0,a.x>>(b-128)};
}
i256 operator&(i256 a,i256 b){
    return{a.x&b.x,a.y&b.y};
}
i256 operator|(i256 a,i256 b){
    return{a.x|b.x,a.y|b.y};
}
i256 operator^(i256 a,i256 b){
    return{a.x^b.x,a.y^b.y};
}
bool operator==(i256 a,i256 b){
    return a.x==b.x&&a.y==b.y;
}
bool operator!=(i256 a,i256 b){
    return a.x!=b.x||a.y!=b.y;
}
int ctz(i256 a){
    if(a.y&(u64)-1)return __builtin_ctzll(a.y);
    if(a.y)return __builtin_ctzll(a.y>>64)+64;
    if(a.x&(u64)-1)return __builtin_ctzll(a.x)+128;
    if(a.x)return __builtin_ctzll(a.x>>64)+192;
    return -1;
}

以上,说的便是我封不觉了

共 5 篇
  1. 生活·游记

    NOI2026 游记

    内容总结:在省选考试中,rk52选手未能进入集训队。两天考试中,选手分别以2小时、3.5小时和部分时间完成各题,得分分别为day1 100+100+25,day2 100+100+28,最终总分558分,但因成绩未达预期而感到焦急。

    27 赞
  2. 题解

    题解:P12073 [OOI 2025] Alice, Bob, and two arrays.

    该代码解决的是两个颜色序列的博弈问题,通过动态规划和区间覆盖优化实现高效计算。核心思路如下: 状态定义:使用win[x][y]表示在数组a移去前x个元素、数组b移去前y个元素时先手是否必胜。 优化策略: 将原序列压缩为颜色段,通过分析颜色段间的转移关系,将复杂度从O(NMk)降至O(NM)。 对于颜色相同的段,利用奇偶性判断胜负:当x-y为定值时,胜负仅取决于x的奇偶性。 数据结构:采用map实现的区间动态树(ODT),维护每个颜色段的区间覆盖信息,支持快速区间更新和单点查询。 转移逻辑: 若填其他颜色可转移到必败态,则当前段先手必胜。 若填其他颜色均转移到必胜态,则双方轮流填当前颜色直至结束,胜负由段长度的奇偶性决定。 查询处理:将每个查询分配到对应的颜色段区间中,通过预处理和区间覆盖快速回答结果。 最终通过奇偶性判断和区间覆盖优化,实现了对大规模数据的高效处理。

    3 赞
  3. 题解

    P12753 [POI 2017 R3] 披萨配送员 Pizza delivery 题解

    该代码通过树形动态规划(DP)结合WQS二分法解决一个与树遍历相关的问题。核心思路是: 树形DP状态设计:定义dp[x][0/1]表示处理完子树x后,快递员是否返回父节点的最短时间,其中dp[x][1]为最终答案。 WQS二分法:引入参数wqs_val,通过二分查找调整该参数,使得满足约束条件k(可能为操作次数或资源限制)。 关键操作: dfs计算初始距离数组dist。 solve函数递归处理子树,通过状态转移合并子节点的路径信息。 二分查找范围为[0, 1e9],最终输出调整后的最短时间减去ans*k。 时间复杂度:整体复杂度为O(n log V),其中V为二分查找的值域范围。 代码旨在优化树遍历路径,确保在满足特定限制条件k的情况下,找到快递员的最短总用时。

    5 赞
  4. 个人记录

    优美的句子摘抄

    在我们倾诉的时候,烦恼衰减了。倾诉者的难过一半交给了对方,另一半随着声波还给了世界。烦恼就这样在人群里越传越弱,直到随风而逝。 我常常追忆过去。 生命瞬间定格在脑海。我将背后的时间裁剪、折叠、蜷曲,揉捻成天上朵朵白云。 云朵之间亦有分别:积云厚重,而卷云飘渺。生命里震撼的场景掠过…

  5. 题解

    题解:P10650 「ROI 2017 Day 1」排序幻觉

    提供一种大常数 01trie 做法。 对于 01trie 的每个节点,我们暴力计算其最大值,最小值并用状态压缩维护答案每一位是否能取 0/1。 具体地,为了保证迅速找到一个节点的最大最小值,我们需要用 set 维护,但为了保证时间复杂度,我们只对叶子节点开 set ,其它的节点类…