当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
About making a progress bar for software initialization for Qt
Hunan institute of technology in 2022 ACM training sixth week antithesis
Induction jian hai JustFE 2022/07/29 team, I learned the efficient development summary (years)
pytroch、tensorflow对比学习—专栏介绍
字符中的第一个唯一字符
【音视频】srs直播平台搭建
Flip letters using string container
移动应用恶意攻击激增500% 三六零天御为APP免费构建安全屏障
Swastika line-by-line parsing and realization of the Transformer, and German translation practice (a)
从离线到实时对客,湖仓一体释放全量数据价值
随机推荐
Selenium:元素定位
MySQL-DML language-database operation language-insert-update-delete-truncate
uva10825
weight distribution
备战金九银十,如何顺利通过互联网大厂Android的笔面试?
NDK does not contain any platforms problem solving
可持久化线段树
CSP-S2019 Day1
DL-31/6电流继电器
曲柄滑块机构运动分析和参数优化
pytorch、tensorflow对比学习—张量
pytorch、tensorflow对比学习—功能组件(激活函数、模型层、损失函数)
【视觉SLAM十四讲】第一章理论详解
类神经网络训练不起来怎么办
ApiFile
matplotlib pyplot
请求/响应拦截器写法
用控件当画笔获得bitmap代码记录
Qt Widget project loading example of qml
Seleniu: Common operations on elements