当前位置:网站首页>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;
}
边栏推荐
- What is uid? What is auth? What is a verifier?
- NFT: utilisez EIP - 2981 pour commencer un voyage de redevances NFT
- Why is Hong Kong server most suitable for overseas website construction
- Tcp/ip explanation (version 2) notes / 3 link layer / 3.4 bridge and switch / 3.4.2 multiple registration protocol (MRP)
- 1. Mobile terminal touch screen event
- Software testing needs more and more talents. Why do you still not want to take this path?
- Tip of edge browser: enter+ctrl can automatically convert the address bar into a web address
- 【发送邮件报错】535 Error:authentication failed
- Programs and processes, process management, foreground and background processes
- 2022危险化学品生产单位安全生产管理人员题库及答案
猜你喜欢

Software testing needs more and more talents. Why do you still not want to take this path?

Extension fragment

This may be your last chance to join Tencent

Possible problems and solutions of using scroll view to implement slider view

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

JD intelligent customer service Yanxi intention system construction and intention recognition technology introduction

Simple implementation of slf4j

2022 question bank and answers for safety production management personnel of hazardous chemical production units

2022 gas examination question bank and online simulation examination

Odeint et GPU
随机推荐
Mallbook: how can hotel enterprises break the situation in the post epidemic era?
2022 gas examination question bank and online simulation examination
Embedded System Development Notes 81: Using Dialog component to design prompt dialog box
Common thread methods and daemon threads
2022 tea master (intermediate) examination question bank and tea master (intermediate) examination questions and analysis
[learn C and fly] S1E20: two dimensional array
离线安装wireshark2.6.10
Maixll-Dock 快速上手
TCP server communication flow
Use winmtr software to simply analyze, track and detect network routing
Ospfb notes - five messages [ultra detailed] [Hello message, DD message, LSR message, LSU message, lsack message]
Redis (VII) optimization suggestions
Seven crimes of counting software R & D Efficiency
[leetcode skimming] February summary (updating)
Unity's 3D multi-point arrow navigation
Rule method: number of effective triangles
2022年聚合工艺考试题及模拟考试
Extension fragment
Registration of P cylinder filling examination in 2022 and analysis of P cylinder filling
How to do the performance pressure test of "Health Code"