当前位置:网站首页>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;
}
边栏推荐
- LM small programmable controller software (based on CoDeSys) note 19: errors do not match the profile of the target
- How to do the performance pressure test of "Health Code"
- Learn Chapter 20 of vue3 (keep alive cache component)
- JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction
- [ue4] event distribution mechanism of reflective event distributor and active call event mechanism
- Valid @suppresswarnings warning name
- slf4j 简单实现
- 扩展-Fragment
- TASK04|数理统计
- JS image path conversion Base64 format
猜你喜欢

软件研发的十大浪费:研发效能的另一面

How to do the performance pressure test of "Health Code"

TASK04|數理統計

Question bank and answers for chemical automation control instrument operation certificate examination in 2022

多次跳槽后,月薪等于老同事的年薪

【深度学习】(4) Transformer 中的 Decoder 机制,附Pytorch完整代码

Chen Yu (Aqua) - Safety - & gt; Cloud Security - & gt; Multicloud security

跳槽一次涨8k,5年跳了3次...

Measurement of quadrature axis and direct axis inductance of three-phase permanent magnet synchronous motor

MallBook:后疫情时代下,酒店企业如何破局?
随机推荐
Spock单元测试框架介绍及在美团优选的实践___第一章
2022 t elevator repair new version test questions and t elevator repair simulation test question bank
Obtain detailed ideas for ABCDEF questions of 2022 American Games
Grey correlation cases and codes
TASK04|数理统计
After many job hopping, the monthly salary is equal to the annual salary of old colleagues
How to choose the right server for website data collection?
VR线上展览所具备应用及特色
2022-02-15 (399. Division evaluation)
NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
[godot] unity's animator is different from Godot's animplayer
Jenkins automatically cleans up construction history
嵌入式系统开发笔记79:为什么要获取本机网卡IP地址
Threejs opening
OSPF notes [multiple access, two multicast addresses with OSPF]
2022危险化学品生产单位安全生产管理人员题库及答案
MySQL advanced -- you will have a new understanding of MySQL
一些小知识点
Collect the annual summary of laws, regulations, policies and plans related to trusted computing of large market points (national, ministerial, provincial and municipal)
2022 a special equipment related management (elevator) simulation test and a special equipment related management (elevator) certificate examination