其他分享
首页 > 其他分享> > Willem, Chtholly and Seniorious

Willem, Chtholly and Seniorious

作者:互联网

Willem, Chtholly and Seniorious

https://codeforces.com/contest/897/problem/E

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

— Willem...

— What's the matter?

— It seems that there's something wrong with Seniorious...

— I'll have a look...

Seniorious is made by linking special talismans in particular order.

After over 500 years, the carillon is now in bad condition, so Willem decides to examine it thoroughly.

Seniorious has n pieces of talisman. Willem puts them in a line, the i-th of which is an integer ai.

In order to maintain it, Willem needs to perform m operations.

There are four types of operations:

Input

The only line contains four integers n, m, seed, vmax (1 ≤ n, m ≤ 105, 0 ≤ seed < 109 + 7, 1 ≤ vmax ≤ 109).

The initial values and operations are generated using following pseudo code:


def rnd():

ret = seed
seed = (seed * 7 + 13) mod 1000000007
return ret

for i = 1 to n:

a[i] = (rnd() mod vmax) + 1

for i = 1 to m:

op = (rnd() mod 4) + 1
l = (rnd() mod n) + 1
r = (rnd() mod n) + 1

if (l > r):
swap(l, r)

if (op == 3):
x = (rnd() mod (r - l + 1)) + 1
else:
x = (rnd() mod vmax) + 1

if (op == 4):
y = (rnd() mod vmax) + 1

Here op is the type of the operation mentioned in the legend.

Output

For each operation of types 3 or 4, output a line containing the answer.

Examples input Copy
10 10 7 9
output Copy
2
1
0
3
input Copy
10 10 9 9
output Copy
1
1
3
3
Note

In the first example, the initial array is {8, 9, 7, 2, 3, 1, 5, 6, 4, 8}.

The operations are:

 

ODT模板题

参考博客:https://blog.csdn.net/niiick/article/details/83062256

  1 #include<bits/stdc++.h>
  2 using namespace std;
  3 #define lson l,mid,rt<<1
  4 #define rson mid+1,r,rt<<1|1
  5 #define IT set<node>::iterator
  6 #define sqr(x) ((x)*(x))
  7 #define pb push_back
  8 #define eb emplace_back
  9 #define maxn 100005
 10 #define eps 1e-8
 11 #define pi acos(-1.0)
 12 #define rep(k,i,j) for(int k=i;k<j;k++)
 13 typedef long long ll;
 14 typedef pair<int,int> pii;
 15 typedef pair<ll,ll>pll;
 16 typedef pair<ll,int> pli;
 17 typedef pair<pair<int,string>,pii> ppp;
 18 typedef unsigned long long ull;
 19 const long long MOD=1e9+7;
 20 const double oula=0.57721566490153286060651209;
 21 using namespace std;
 22 
 23 struct node{
 24     int l,r;
 25     mutable ll val;
 26     node(int L,int R=-1,ll V=0):l(L),r(R),val(V){}
 27     bool operator<(const node& t)const {
 28         return l<t.l;
 29     }
 30 };
 31 set<node>se;
 32 
 33 ll ksm(ll a,ll b,ll mod){
 34     ll ans=1;
 35     a%=mod;
 36     while(b){
 37         if(b&1){
 38             ans=(ans*a)%mod;
 39         }
 40         b>>=1;
 41         a=(a*a)%mod;
 42     }
 43     return ans;
 44 }
 45 
 46 IT split(int pos){
 47     IT it=se.lower_bound(node(pos));
 48     if(it!=se.end()&&it->l==pos) return it;
 49     it--;
 50     int L=it->l,R=it->r;
 51     ll V=it->val;
 52     se.erase(it);
 53     se.insert(node(L,pos-1,V));
 54     return se.insert(node(pos,R,V)).first;///返回L==pos的迭代器
 55 }
 56 
 57 void assign(int l,int r,ll v){
 58     IT itr=split(r+1),itl=split(l);
 59     se.erase(itl,itr);///左闭右开
 60     se.insert(node(l,r,v));
 61 }
 62 
 63 void add(int l,int r,ll v){
 64     IT itr=split(r+1);
 65     for(IT itl=split(l);itl!=itr;itl++){
 66         itl->val+=v;
 67     }
 68 }
 69 
 70 ll Rank(int l,int r,int v){
 71     IT itr=split(r+1);
 72     vector<pli>tmp;
 73     for(IT itl=split(l);itl!=itr;itl++){
 74         tmp.pb({itl->val,itl->r-itl->l+1});
 75     }
 76     sort(tmp.begin(),tmp.end());
 77     for(int i=0;i<tmp.size();i++){
 78         v-=tmp[i].second;
 79         if(v<=0){
 80             return tmp[i].first;
 81         }
 82     }
 83 }
 84 
 85 ll query(int l,int r,ll x,ll y){
 86     IT itr=split(r+1);
 87     ll ans=0;
 88     for(IT itl=split(l);itl!=itr;itl++){
 89         ans=(ans+((ksm(itl->val,x,y)*(itl->r-itl->l+1))%y))%y;
 90     }
 91     return ans;
 92 }
 93 
 94 ll n,m,seed,vmax;
 95 
 96 ll rnd(){
 97     ll ans=seed;
 98     seed=(seed*7+13)%MOD;
 99     return ans;
100 }
101 
102 
103 int main(){
104     std::ios::sync_with_stdio(false);
105 
106     cin>>n>>m>>seed>>vmax;
107     ll x,y;
108     for(int i=1;i<=n;i++){
109         x=(rnd()%vmax)+1;
110         se.insert(node(i,i,x));
111     }
112     int opt,L,R;
113     for(int i=1;i<=m;i++){
114         opt=(rnd()%4)+1;
115         L=(rnd()%n)+1;
116         R=(rnd()%n)+1;
117         if(L>R) swap(L,R);
118         if(opt==3){
119             x=(rnd()%(R-L+1))+1;
120         }
121         else{
122             x=(rnd()%vmax)+1;
123         }
124         if(opt==4){
125             y=(rnd()%vmax)+1;
126         }
127         if(opt==1){
128             add(L,R,x);
129         }
130         else if(opt==2){
131             assign(L,R,x);
132         }
133         else if(opt==3){
134             cout<<Rank(L,R,x)<<endl;
135         }
136         else{
137             cout<<query(L,R,x,y)<<endl;
138         }
139     }
140 }
View Code

 

标签:Willem,Chtholly,itl,int,ll,Seniorious,rnd,seed,mod
来源: https://www.cnblogs.com/Fighting-sh/p/10584244.html