2022牛客暑期多校训练营2

比赛链接

2022牛客暑期多校训练营2

D. Jobs (Easy Version)

N 公司,每个公司提供 mi 个岗位,每个岗位有三个限制条件 IQEQ,AQ 。只有自己的三个值都大于等于该岗位的限 制,该公司才会发offer。现有 Q 个人问,每个人可以收到几个公司的offer。
数据范围

1<=n<=10,1<=m<1e5,1<=Q<=2e6,1<=IQ,EQ,AQ<=400

解题思路

二维树状数组

即插入许多三元组 (a,b,c),每次询问 (x,y,z),找出是否存在 xa,yb,zc,可以建立 n 棵二维树状数组,a,b 分别作为树状数组的下标,树状数组维护小于等于 ab 的最小的 c

  • 时间复杂度:O(qlog2400)

代码

// Problem: Jobs (Easy Version) // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/33189/D // Memory Limit: 1048576 MB // Time Limit: 6000 ms // // Powered by CP Editor (https://cpeditor.org) // %%%Skyqwq #include <bits/stdc++.h> // #define int long long #define help {cin.tie(NULL); cout.tie(NULL);} #define pb push_back #define fi first #define se second #define mkp make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; } template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } const int N=405,M=2e6+5,mod=998244353; int tr[15][N][N],seed,n,q,m,a,b,c,t[M]; void add(int id,int x,int y,int k) { for(int i=x;i<N;i+=i&-i) for(int j=y;j<N;j+=j&-j)tr[id][i][j]=min(tr[id][i][j],k); } int ask(int id,int x,int y) { int res=0x3f3f3f3f; for(int i=x;i;i-=i&-i) for(int j=y;j;j-=j&-j)res=min(res,tr[id][i][j]); return res; } int solve(int a,int b,int c) { int res=0; for(int i=1;i<=n;i++) if(c>=ask(i,a,b))res++; return res; } int main() { help; memset(tr,0x3f,sizeof tr); cin>>n>>q; for(int i=1;i<=n;i++) { cin>>m; for(int j=1;j<=m;j++) { cin>>a>>b>>c; add(i,a,b,c); } } cin>>seed; t[0]=1; for(int i=1;i<M;i++)t[i]=1ll*seed*t[i-1]%mod; std::mt19937 rng(seed); std::uniform_int_distribution<> u(1, 400); int lastans=0; int res=0; for(int i=1;i<=q;i++) { int IQ = (u(rng) ^ lastans) % 400 + 1; // The IQ of the i-th friend int EQ = (u(rng) ^ lastans) % 400 + 1; // The EQ of the i-th friend int AQ = (u(rng) ^ lastans) % 400 + 1; // The AQ of the i-th friend lastans=solve(IQ,EQ,AQ); res=(1ll*res+1ll*lastans*t[q-i])%mod; } cout<<res; return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/16538601.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(49)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示