当前位置:网站首页>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;
}
边栏推荐
- Web server: how to choose a good web server these five aspects should be paid attention to
- OdeInt与GPU
- 什么是uid?什么是Auth?什么是验证器?
- Internet winter, how to spend three months to make a comeback
- Task04 mathematical statistics
- Applications and features of VR online exhibition
- JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
- 2022年T电梯修理题库及模拟考试
- Why is Hong Kong server most suitable for overseas website construction
- 测量三相永磁同步电机的交轴直轴电感
猜你喜欢

slf4j 简单实现
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET

Threejs opening

Dual Contrastive Learning: Text Classification via Label-Aware Data Augmentation 阅读笔记

尺取法:有效三角形的个数

Programs and processes, process management, foreground and background processes

Offline installation of Wireshark 2.6.10

Maixll-Dock 快速上手
![[recommended algorithm] C interview question of a small factory](/img/ae/9c83efe86c03763710ba5e4a2eea33.jpg)
[recommended algorithm] C interview question of a small factory

Applications and features of VR online exhibition
随机推荐
Web server: how to choose a good web server these five aspects should be paid attention to
[today in history] June 30: von Neumann published the first draft; The semiconductor war in the late 1990s; CBS acquires CNET
2022年煤气考试题库及在线模拟考试
Embedded System Development Notes 81: Using Dialog component to design prompt dialog box
Odeint and GPU
slf4j 简单实现
TCP server communication flow
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
2022年聚合工艺考试题及模拟考试
【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码
2022 gas examination question bank and online simulation examination
mysql 函数 变量 存储过程
2022 polymerization process test questions and simulation test
【LeetCode】100. Same tree
Rule method: number of effective triangles
283. move zero
Jenkins automatically cleans up construction history
Ten wastes of software research and development: the other side of research and development efficiency
Grey correlation cases and codes
Tencent has five years of testing experience. It came to the interview to ask for 30K, and saw the so-called software testing ceiling