当前位置:网站首页>More than 2022 cattle guest school game 4 yue
More than 2022 cattle guest school game 4 yue
2022-08-01 05:34:00 【Vegetable newbie】
2022In cattle guest multi-universities' game 4 yue
D.Jobs (Easy Version)
题意
q q qPeople looking for a job,有 n n n家公司,Every company has m m m个工作,Each and every job has 3 3 3个属性 a , b , c a,b,c a,b,c,If and only if each person a , b , c a,b,c a,b,cHave more than one job a , b , c a,b,c a,b,c,This talent can successfully complete this work,If a person can complete a job in a company,Then the company will be him.Each person's attributes are made for you s e e d seed seedAs the random number seed and on a person's answer,进行随机生成.
计算
( ∑ i = 1 n a n s i ∗ s e e d q − i ) m o d 998244353 (\sum_{i =1}^n ans_i * seed ^ {q - i}) mod998244353 (∑i=1nansi∗seedq−i)mod998244353
a n s i ans_i ansi表示第iHow many individual companies are willing to accept him
数据范围
1 ⩽ n ⩽ 10 1 \leqslant n \leqslant 10 1⩽n⩽10
1 ⩽ q ⩽ 2 ∗ 1 0 6 1 \leqslant q \leqslant 2 * 10 ^ 6 1⩽q⩽2∗106
1 ⩽ m ⩽ 1 0 5 1 \leqslant m \leqslant 10^5 1⩽m⩽105
1 ⩽ a i , b i , c i ⩽ 400 1 \leqslant a_i, b_i, c_i \leqslant 400 1⩽ai,bi,ci⩽400
思路
由于有 q q q个人了,The answer to the query one time complexity is in log ( m ∗ n ) \log{(m * n)} log(m∗n),Can think first pretreatment out to the company i i iThe ability of a value can be up to, 然后 O ( 1 ) O(1) O(1)进行查询.
预处理,The four dimensions b o o l bool boolArray would burst memory,所以用 b i t s e t bitset bitset进行压位, d p dp dp一下: d p [ i ] [ a ] [ b ] [ c ] dp[i][a][b][c] dp[i][a][b][c]A person's ability to attribute value as a , b , c a, b, c a,b,cCan be up to the company i i i.
时间复杂度
O ( n ∗ 40 0 3 ) O(n * 400 ^ 3) O(n∗4003)
可以优化的地方
1.Can be optimized into 3 d
2.语言选择 C + + ( g + + 7.5.0 ) C++(g++ 7.5.0) C++(g++7.5.0),选 C + + ( c l a n g + + 11.0.1 ) C++(clang++ 11.0.1) C++(clang++11.0.1)就超时了.
3.In the middle of the fast power can first pretreatment can come out a little l o g log log.
代码:
#include <bits/stdc++.h>
#pragma gcc optimize("O2")
#pragma g++ optimize("O2")
//#define int long long
#define endl '\n'
using namespace std;
const int N = 2e5 + 10, MOD = 998244353;
int n, q, x, y, z;
int k1,k2,k3,k4;
bitset<402>fk[11][401][401];
inline int getid(int x,int y,int z){
return 160801*(x)+(y)*(401)+z;
}
int getans(int iq, int eq, int aq){
int ans=0;
for(int i=1;i<=n;i++){
ans+=fk[i][iq][eq][aq];
}
return ans;
}
int binpow(long long x, int y, int mod, long long res = 1){
for (; y; y >>= 1, (x *= x) %= mod) if (y & 1) (res *= x) %= mod;
return res;
}
int powq[2000010];
inline void solve(){
cin >> n >> q;
for(int i = 1; i <= n; i++){
cin >> k1;
for(int j = 1; j <= k1; j++) {
cin>>x>>y>>z;
fk[i][x][y][z]=1;
}
}
for(short i=1;i<=n;i++){
for(short j=1;j<=400;j++){
for(short k=1;k<=400;k++){
for(short x=1;x<=400;x++){
fk[i][j][k][x]=fk[i][j][k][x]|fk[i][j][k][x-1]|fk[i][j][k-1][x]|fk[i][j-1][k][x];
}
}
}
}
int seed; cin >> seed;
powq[0] = 1;
for(int i = 1; i <= 2000000 + 5; i++){
powq[i] = 1ll * powq[i - 1] * seed % MOD;
}
std::mt19937 rng(seed);
std::uniform_int_distribution<> u(1, 400);
int lastans = 0, ans = 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 = getans(IQ, EQ, AQ); // The answer to the i-th friends
(ans += (1ll * lastans * powq[q - i] % MOD)) %= MOD;
}
cout << (ans % MOD) << endl;
}
signed main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout << fixed << setprecision(12);
int t = 1;
while(t--) solve();
return 0;
}
边栏推荐
猜你喜欢
WebSocket implements chat function
可视化全链路日志追踪
MySQL-Data Operation-Group Query-Join Query-Subquery-Pagination Query-Joint Query
PaddleX部署推理模型和GUI界面测试结果不一致的解决方法
Selenium: Manipulating Cookies
I met a shell script
Flip letters using string container
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
Robot_Framework: keyword
Hunan institute of technology in 2022 ACM training sixth week antithesis
随机推荐
weight distribution
小白的0基础教程SQL: 关系数据库概述 02
2022年超全的Android面经(附含面试题|进阶资料)
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
MySQL-Data Operation-Group Query-Join Query-Subquery-Pagination Query-Joint Query
【MySQL必知必会】 表的优化 | 充分利用系统资源
Robot_Framework: commonly used built-in keywords
Jupyter shortcuts
HJS-DE1/2时间继电器
Qt Widget project loading example of qml
数据湖:数据同步工具NiFi
微信小程序接口调用凭证(获取token)auth.getAccessToken接口开发
JS的运行原理
ORACLE 实现另外一个用户修改包(package)
Selenium: element judgment
pytroch、tensorflow对比学习—搭建模型范式(构建模型方法、训练模型范式)
How JS works
【视觉SLAM十四讲】第一章理论详解
零序电流继电器器JL-8C-12-2-2
CSP-S2019兴奋不已