颓废记

· · 个人记录

不想写题,那就随便写点东西

模拟赛

10.26 模拟赛

爱挑战。

T1

啥子数据量,直接状压秒了。

::::success[code]

#include <cstdio>
char buf[1000010], obuf[1000010], *p1, *p2, *p3=obuf;
#define gc (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1000000, stdin), p1==p2) ? EOF : *p1++)
#define pc(x) (p3==obuf+1000000&&fwrite(p3=obuf, 1, 1000000, stdout), *p3++=(x))
#define ll unsigned long long
#define ui unsigned int
#define N 1000005
#define tT template<typename T>
#define tA template<typename T, typename... Ts>
using namespace std;
const ui _2[6]= { 1, 2, 4, 8, 16, 32 } ;
namespace M_K_W_ {
    tT inline void read(T& x) {
        x=0; char ch=gc; while(ch<'0'||ch>'9') ch=gc;
        while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=gc;
    }
    tA inline void read(T& x, Ts&... args) { read(x); read(args...); }
    tT inline void write(T x) {
        if(x==0) { pc('0'); return ; }
        static ui a[40]; ui t=0; while(x) a[++t]=x%10, x/=10; while(t) pc(a[t--]|48);
    }
    tT inline void S(T& a, T& b) { a^=b, b^=a, a^=b; }
    struct Edge { ui to, nxt; } edge[N<<1];
    ui n, m, k, a[N], x, y, head[N], idx, t[N], c;
    ll f[N][32], ans;
    inline void add(const ui u, const ui v) {
        edge[++idx].to=v, edge[idx].nxt=head[u], head[u]=idx;
    }
    inline ui ppc(ui x) { ui res=0; while(x) x-=(x&-x), ++res; return res; }
    inline void solve() {
        read(n, m, k);
        for(ui i=1; i<=n; ++i)
            read(a[i]), f[i][a[i]=_2[a[i]-1]]=1;
        for(ui i=1; i<=m; ++i)
            read(x, y), add(x, y), add(y, x);
        for(ui j=1; j<_2[k]; ++j)
            if(j>(j&-j))
                for(ui u=1; u<=n; ++u)
                    if(a[u]&j) {
                        for(ui i=head[u]; i; i=edge[i].nxt)
                            f[u][j]+=f[edge[i].to][j^a[u]];
                        ans+=f[u][j];
                    }
        write(ans);
    }
}
int main() { M_K_W_ :: solve(); fwrite(obuf, 1, p3-obuf, stdout); return 0; }

::::

T2

我非常爱挑战,所以我通过了这个题。

这个强连通分量可以是假的,还是考虑算一个边可以贡献的区间,类似于一些毛毛虫区间。 ``` [l1,r1],[l2,r2],...,[lt,rt] l1<=l2<=...<=lt,r1<=r2<=...<=rt 这些区间内部小区间肯定能更新。 ``` 我们直接暴力算出这些区间,然后再把这些区间拍到一个映射上,把询问离线下来做扫描线二维数点统答案。 讲完了,然后开始挑战写代码,赛时也是通过了。 但是发现事情并没有这么简单。 原题数据轻松 T 了,经过简单卡常后 M 了,为什么呢? 发现把这些毛毛虫区间统下来非常耗费空间,他最多支持我们存一遍,原区间和映射加起来肯定开不下,链式也没有用。 直接上绝招,原区间链式存下来,发现更新映射时对应毛毛虫期间只会更新当前映射,直接把链表变异,写两个 `nxt`,把原区间的原值 100% 回收下来,只浪费一个 `nxt` 的空间足够了。 然后就能愉快通过原题了。 ::::success[code] ```cpp #include <cstdio> #include <algorithm> char buf[1000010], obuf[2000010], *p1, *p2, *p3=obuf; #define gc (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1000000, stdin)), *p1++) #define ll unsigned long long #define ui unsigned int #define N 502 #define M 100002 #define E 49900001 #define tT template<typename T> #define tA template<typename T, typename... Ts> namespace M_K_W_ { tT inline void read(T& x) { x=0; char ch=gc; while(ch<'0'||ch>'9') ch=gc; while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch&15), ch=gc; } tA inline void read(T& x, Ts&... args) { read(x); read(args...); } inline void write(ll x) { if(x==0) { *p3++='0'; return ; } static ui a[25]; ui t=0; while(x) a[++t]=x%10, x/=10; while(t) *p3++=a[t--]|48; } inline ui max(const ui a, const ui b) { return a>b ? a : b; } struct Edge { ui v, w, nxtF, nxtG; } e[E]; struct Q { ui x, y, i; inline void Rd(const ui j) { read(x, y); i=j; } bool operator < (const Q& z) const { return x<z.x; } } a[M]; ui n, m, q, x, y, fa[N], f[N], dis[N], dep[N], id[N], R[M], G[M], F[M], idx; ll z[M], w[N], fx[M], fy[M], ans[M]; inline ui Find(const ui x) { return x==f[x] ? x : f[x]=Find(f[x]); } inline void mer(const ui x, const ui y) { if(fa[x]) mer(fa[x], x); fa[x]=y, w[x]=w[y], id[x]=id[y]; } inline void merge(const ui x, const ui y, const ui xx, const ui yy, const ll z, const ui Id) { f[yy]=xx, dis[xx]+=dis[yy], mer(y, x), w[y]=z, id[y]=Id; } inline void fun(const ui k) { if(fa[k]) fun(fa[k]), dep[k]=dep[fa[k]]+1; else dep[k]=1; } inline void Gad(const ui u, const ui v, const ui w) { e[++idx].v=v, e[idx].nxtG=G[u], e[idx].w=w, G[u]=idx; } inline ui get(ui x, ui y) { ui res, min_id=m; while(dep[x]>dep[y]) { if(min_id>id[x]) res=x, min_id=id[x]; x=fa[x]; } while(dep[y]>dep[x]) { if(min_id>id[y]) res=y, min_id=id[y]; y=fa[y]; } while(x!=y) { if(min_id>id[x]) res=x, min_id=id[x]; if(min_id>id[y]) res=y, min_id=id[y]; x=fa[x], y=fa[y]; } return res; } inline void del_merge(const ui t, const ui ni, const ui sx, const ui sy, const ll z) { ui x=sx, y=sy; while(dep[x]>dep[y]) { if(id[x]!=id[t]) e[G[id[x]]].w=ni-1, Gad(id[x], max(id[t]+1, e[G[id[x]]].v), 0); x=fa[x]; } while(dep[y]>dep[x]) { if(id[y]!=id[t]) e[G[id[y]]].w=ni-1, Gad(id[y], max(id[t]+1, e[G[id[y]]].v), 0); y=fa[y]; } while(x!=y) { if(id[x]!=id[t]) e[G[id[x]]].w=ni-1, Gad(id[x], max(id[t]+1, e[G[id[x]]].v), 0); if(id[y]!=id[t]) e[G[id[y]]].w=ni-1, Gad(id[y], max(id[t]+1, e[G[id[y]]].v), 0); x=fa[x], y=fa[y]; } fa[t]=w[t]=id[t]=0; mer(sy, sx), w[sy]=z, id[sy]=ni; } inline void upd(ui i, const ll x) { for(; i<=m; i+=(i&-i)) fx[i]+=x; } inline ll gs(ui i) { ll r=0; while(i) r+=fx[i], i-=(i&-i); return r; } inline void upd2(ui i, const ll x) { for(; i<=m; i+=(i&-i)) fy[i]+=x; } inline ll gs2(ui i) { ll r=0; while(i) r+=fy[i], i-=(i&-i); return r; } inline void solve() { read(n, m, q); for(ui i=1; i<=n; ++i) dis[f[i]=i]=1; for(ui i=1; i<=m; ++i) { read(x, y, z[i]); const ui xx=Find(x), yy=Find(y); if(xx!=yy) { if(dis[yy]<dis[xx]) merge(y, x, yy, xx, z[i], i), Gad(i, 1, 0); else merge(x, y, xx, yy, z[i], i), Gad(i, 1, 0); } else { fun(x), fun(y); const ui t=get(x, y); e[G[id[t]]].w=i-1, Gad(i, id[t]+1, 0), del_merge(t, i, x, y, z[i]); } } for(ui u=1; u<=m; ++u) { if(!e[G[u]].w) e[G[u]].w=m; for(ui i=G[u]; i; i=e[i].nxtG) e[i].nxtF=F[e[i].v], F[e[i].v]=i, e[i].v=u; } for(ui i=1; i<=q; ++i) a[i].Rd(i); std::sort(a+1, a+1+q); for(ui k=1, u=0, v=1; k<=q; ++k) { while(u<a[k].x) for(ui i=F[++u]; i; i=e[i].nxtF) { const ui x=e[i].w, y=e[i].v; upd(x, z[y]), upd2(y, z[y]); if(R[y]) { const ll o=0ull-z[y]; upd(R[y], o), upd2(y, o); } R[y]=x; } while(v<a[k].x) { if(R[v]) { const ll o=0ull-z[v]; upd(R[v], o), upd2(v, o); } ++v; } ans[a[k].i]=gs2(a[k].y)-gs(a[k].y-1); } for(ui i=1; i<=q; ++i) write(ans[i]), *p3++='\n'; } } int main() { M_K_W_ :: solve(); fwrite(obuf, 1, p3-obuf, stdout); return 0; } ``` :::: wjy 赛场大战后两题成功后比赛结束,并表示绝对不补这个题,这个题绝对没那么好写。 ### ? 后两题没补,感觉太难。打了点小包。也就是说,是我赢了。 ## 10.28 模拟赛 我生气了,信心场但是滚木,前两个唐写了一整场,没时间写 T3,T4 成功假算否掉真算获得滚木,T3,补题放错了,没有 T3,反正应该是都补完了。 ## 11.3 模拟赛 这个 T1 怎么这么难。这个 zmj 怎么这么神经。这个电脑怎么这么卡。这个代码怎么都在桌面上。这个电脑我给他重启了。我好生气,我要睡觉。怎么只有 2h 了。什么叫没切 T1 260pts 仅低于 300+ 的人类。 ### [T1](https://qoj.ac/problem/7617) 赛时我是大啥子,把包拼满了获得 60pts。 相邻两人建边,把边排个序,做 kruskal,一定大小的集合答案能算,边合并边算就对了。 没有代码,非常生气,遂咕咕。 ### [T2](https://repovive.com/contests/23/problems/E) 没啥印象了,简单题。好像是单调栈正着倒着扫一遍就做完了。 代码没存。 ### [T3](https://www.luogu.com.cn/problem/P14389) 黄题,直接爆搜就对了。用并查集倒腾一下,AI 说复杂度是 $\Theta(n\alpha(n))$ 的,轻松最优解,那就是爆标了。 具体忘了,赛时偷懒写的 $\Theta(n\log)$,二分的,不然要预处理个前后继状物。 代码卡常内存回收使得完全不可读了,我不放了。 ### [T4](https://repovive.com/contests/27/problems/G) 难飞了。 ## 11.6 模拟赛 ### [T1](https://www.luogu.com.cn/problem/P6221) [板子](https://www.luogu.com.cn/article/3eb59smv) ### [T2](https://www.luogu.com.cn/problem/P10761) [板子](https://www.luogu.com.cn/article/m71n49hq) ### [T3](https://www.luogu.com.cn/problem/P9522) 相当于给两种限制,限制内容类似于连续一段相等然后第一个位置前者字符小于或大于后者。 把这两种限制拍到一个桶上,用 set 维护哪些限制还有效,dp 状态就是当前位填什么字母,拿出 set 里面距离当前位置最大的那个左端点,算出转移数组,做前缀和优化 dp。 ::::success[code] ```cpp #include <bits/stdc++.h> char buf[1000010], obuf[1000010], *p1, *p2, *p3=obuf; #define gc (p1==p2&&(p2=(p1=buf)+fread(buf, 1, 1000000, stdin), p1==p2) ? EOF : *p1++) #define pc(x) (p3==obuf+1000000&&fwrite(p3=obuf, 1, 1000000, stdout), *p3++=(x)) #define LF pc('\n') #define SP pc(' ') #define ll unsigned long long #define ui unsigned int #define N 1000005 #define INF 0x3f3f3f3f #define mod 1000000007 #define tT template<typename T> #define tA template<typename T, typename... Ts> using namespace std; namespace FastIO { tT inline void read(T& x) { x=0; char ch=gc; while(ch<'0'||ch>'9') ch=gc; while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48), ch=gc; } tA inline void read(T& x, Ts&... args) { read(x); read(args...); } tT inline void write(T x) { if(x==0) return (void)pc('0'); if(x<0) x=-x, pc('-'); static ui a[40]; ui t=0; while(x) a[++t]=x%10, x/=10; while(t) pc(a[t--]|48); } tA inline void write(T x, Ts... args) { write(x); if(sizeof...(args)!=0) { SP; write(args...); } } } using namespace FastIO; namespace M_K_W_ { tT inline T ad(const T x) { return x<mod ? x : x-mod; } ui n, m, a, b, f[N][26], g[26], ans, G[N], G2[N]; vector<ui> F[N], F2[N]; multiset<ui> p, q; inline void solve() { read(n, m); for(ui i=1; i<=m; ++i) { read(a, b); if(a<b) ++G[a], F[b].emplace_back(a); else if(a>b) ++G2[b], F2[a].emplace_back(b); } p.insert(0), q.insert(0); for(ui i=0; i<26; ++i) f[1][i]=1; for(ui i=0; i<G[1]; ++i) p.insert(1); for(ui i=0; i<G2[1]; ++i) q.insert(1); for(ui i=2; i<=n; ++i) { const ui y=i-1; for(ui j=0; j<26; ++j) f[i][j]=f[y][j]; ui k=*p.rbegin(), sum=0; for(ui j=0; j<26; ++j) g[j]=ad(f[y][j]+mod-f[k][j]); for(ui j=26; ~j; --j) f[i][j]=ad(f[i][j]+sum), sum=ad(sum+g[j]); k=*q.rbegin(), sum=0; for(ui j=0; j<26; ++j) g[j]=ad(f[y][j]+mod-f[k][j]); for(ui j=0; j<26; ++j) f[i][j]=ad(f[i][j]+sum), sum=ad(sum+g[j]); for(ui t : F[i]) p.erase(p.find(t)); for(ui t : F2[i]) q.erase(q.find(t)); for(ui j=0; j<G[i]; ++j) p.insert(i); for(ui j=0; j<G2[i]; ++j) q.insert(i); } for(ui j=0; j<26; ++j) ans=ad(ans+f[n][j]); write(ans); } } int main() { M_K_W_ :: solve(); fwrite(obuf, 1, p3-obuf, stdout); return 0; } ``` :::: ### [T4](https://repovive.com/contests/20/problems/G) 咕。 ## 11.9 模拟赛 神秘困难模拟赛获得单调不降分数。 ### [T1]()