当前位置:网站首页>Codeworks round 449 (Div. 1) C. Kodori tree template
Codeworks round 449 (Div. 1) C. Kodori tree template
2022-07-01 04:36:00 【HeartFireY】
Kodori tree template , It is required to support interval power sum , Pay attention to the details don't hang up .
Be careful Explosive long long!!!
#include <bits/stdc++.h>
using namespace std;
#define int long long
struct node{
int l, r;
mutable int val;
node (int lpos): l(lpos) {
}
node (int lpos, int rpos, int vall): l(lpos), r(rpos), val(vall) {
}
bool operator< (const node &a) const {
return l < a.l; }
};
set<node> s;
using sit = set<node>::iterator;
sit split(int pos){
sit it = s.lower_bound(node(pos));
if(it != s.end() && it -> l == pos) return it;
--it;
int l = it -> l, r = it -> r, val = it -> val;
s.erase(it);
s.insert(node(l, pos - 1, val));
return s.insert(node(pos, r, val)).first;
}
void assign(int l, int r, int val){
sit itr = split(r + 1), itl = split(l);
s.erase(itl, itr);
s.insert(node(l, r, val));
}
void add(int l, int r, int val){
sit itr = split(r + 1), itl = split(l);
//for(auto it = itl; it != itr; it++) it -> val += val;
while(itl != itr) itl -> val += val, itl++;
}
int kth(int l, int r, int k){
sit itr = split(r + 1), itl = split(l);
vector<pair<int, int>> v;
v.clear();
for(sit it = itl; it != itr; it++) v.emplace_back(make_pair(it -> val, it -> r - it -> l + 1));
sort(v.begin(), v.end());
for(int i = 0; i < v.size(); i++){
k -= v[i].second;
if(k <= 0) return v[i].first;
}
return -1;
}
int binpow(int x, int y, int mod, int res = 1){
for (x %= mod; y; y >>= 1, (x *= x) %= mod) if (y & 1) (res *= x) %= mod;
return res;
}
int query(int l, int r, int x, int y){
sit itr = split(r + 1), itl = split(l);
int res(0);
for(sit it = itl; it != itr; it++)
res = (res + (it -> r - it -> l + 1) * binpow(it -> val, x, y)) % y;
return res;
}
int n, m, vmax, seed;
int rnd() {
int ret = (int)seed;
seed = (seed * 7 + 13) % 1000000007;
return ret;
}
inline void solve(){
cin >> n >> m >> seed >> vmax;
for(int i = 1; i <= n; i++){
int a = rnd() % vmax + 1;
s.insert(node{
i, i, (int) a});
}
s.insert(node{
n + 1, n + 1, 0});
for(int i = 1; i <= m; i++){
int l, r, x, y;
int op = rnd() % 4 + 1;
l = rnd() % n + 1, r = rnd() % n + 1;
if(l > r) swap(l, r);
if(op == 3) x = rnd() % (r - l + 1) + 1;
else x = rnd() % vmax + 1;
if(op == 4) y = rnd() % vmax + 1;
if(op == 1) add(l, r, x);
else if(op == 2) assign(l, r, x);
else if(op == 3) cout << kth(l, r, x) << endl;
else if(op == 4) cout << query(l, r, x, y) << endl;
}
}
signed main(){
solve();
return 0;
}
边栏推荐
- Maixll dock quick start
- CUDA development and debugging tool
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- 多次跳槽后,月薪等于老同事的年薪
- 总结全了,低代码还需要解决这4点问题
- 使用WinMTR软件简单分析跟踪检测网络路由情况
- Offline installation of Wireshark 2.6.10
- Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
- Dual contractual learning: text classification via label aware data augmentation reading notes
- Maixll-Dock 使用方法
猜你喜欢

"Target detection" + "visual understanding" realizes the understanding of the input image

测量三相永磁同步电机的交轴直轴电感

Grey correlation cases and codes

CF1638E colorful operations

2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination

2022 t elevator repair question bank and simulation test

After many job hopping, the monthly salary is equal to the annual salary of old colleagues

Unity's 3D multi-point arrow navigation

Odeint et GPU

Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
随机推荐
How to ensure the idempotency of the high concurrency interface?
Offline installation of Wireshark 2.6.10
Loop filtering based on Unet
LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
Day 52 - tree problem
Coinbase in a bear market: losses, layoffs, stock price plunges
2022-02-15 (399. Division evaluation)
Jenkins automatically cleans up construction history
软件研发的十大浪费:研发效能的另一面
NFT: start NFT royalty journey with eip-2981
2022危险化学品生产单位安全生产管理人员题库及答案
Do280 management application deployment --rc
Introduction of Spock unit test framework and its practice in meituan optimization___ Chapter I
ThreeJS开篇
mysql 函数 变量 存储过程
Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security
How to do the performance pressure test of "Health Code"
Announcement on the list of Guangdong famous high-tech products to be selected in 2021
PgSQL failed to start after installation