8 provincial election simulation

A. sequence

Discovery is harder to maintain after a message.

So consider the direct block maintenance.

Open a vector for each block, the block that represents all of the elements in the vector of all the elements taken sequentially through the max.

Max is taken as the nature, the elements of this vector only needs to retain a monotonically increasing portion.

When the query and violence reconstructed some of the blocks, they can directly determine the vector in half an element is updated many times.

Because the memory card, so every 5000 asking reconstruction violence once all blocks.

When asked to hand cheap upperbound labeled as lowerbound, crying.

 1 #include<bits/stdc++.h>
 2 #define ll long long
 3 using namespace std;
 4 const int N=1e5+7;
 5 int n,m,sq;
 6 ll a[N],add[700];
 7 int sz[N],bl[N],tim[700];
 8 vector<ll> ve[700];
 9 inline void rebuild(int k){
10     if(!tim[k]&&ve[k].empty()) return ; 
11     int l=(k-1)*sq+1,r=min(n,k*sq);
12     for(int i=l;i<=r;++i){
13         sz[i]+=ve[k].end()-upper_bound(ve[k].begin(),ve[k].end(),a[i])+tim[k];
14         if(!ve[k].empty()) a[i]=max(a[i],ve[k].back())+add[k];
15         else a[i]+=add[k];
16     }
17     tim[k]=0; add[k]=0; ve[k].clear();
18 }
19 inline void modify(int l,int r,int c){
20     if(!c) return ;
21     rebuild(bl[l]); rebuild(bl[r]);
22     for(int i=l,lim=min(bl[l]*sq,r);i<=lim;++i) ++sz[i],a[i]+=c;
23     if(bl[l]!=bl[r]) for(int i=(bl[r]-1)*sq+1;i<=r;++i) ++sz[i],a[i]+=c;
24     for(int i=bl[l]+1;i<bl[r];++i) add[i]+=c,++tim[i];
25 }
26 inline void insert(int l,int r,int c){
27     rebuild(bl[l]); rebuild(bl[r]);
28     for(int i=l,lim=min(bl[l]*sq,r);i<=lim;++i) if(c>a[i]) a[i]=c,++sz[i];
29     if(bl[l]!=bl[r]) for(int i=(bl[r]-1)*sq+1;i<=r;++i) if(c>a[i]) a[i]=c,++sz[i];
30     for(int i=bl[l]+1;i<bl[r];++i) if(ve[i].empty()||c-add[i]>ve[i].back()) ve[i].push_back(c-add[i]);
31 }
32 inline void query(int x){
33     int k=bl[x];
34     if(!ve[k].empty()) printf("%lld ",max(a[x],ve[k].back())+add[k]);
35     else printf("%lld ",a[x]+add[k]);
36     printf("%d\n",sz[x]+ve[k].end()-upper_bound(ve[k].begin(),ve[k].end(),a[x])+tim[k]);
37 }
38 inline int read(register int x=0,register char ch=getchar(),register int f=0){
39     for(;!isdigit(ch);ch=getchar()) f=ch=='-';
40     for(; isdigit(ch);ch=getchar()) x=(x<<1)+(x<<3)+(ch^48);
41     return f?-x:x;
42 }
43 int main(){
44     n=read(); sq=sqrt(n)*0.5+1;
45     for(int i=1;i<=n;++i) a[i]=read(),bl[i]=(i-1)/sq+1;
46     m=read();
47     for(int i=1,l,r,c;i<=m;++i){
48         char ch=getchar(); while(!isalpha(ch)) ch=getchar();
49         if(ch=='A') l=read(),r=read(),c=read(),modify(l,r,c);
50         else if(ch=='M') l=read(),r=read(),c=read(),insert(l,r,c);
51         else query(read());
52         if(!(i&4095)) for(int j=1;j<=bl[n];++j) rebuild(j);
53     }
54     return 0;
55 }
Block

Reconstruct the time-complexity of violence bottleneck modifications, complexity is $ O (n \ sqrt {nlogn}) $.

Reconstruction can be found in the monotone pointer, maintaining the order of elements in each block, the operation can be modified for Merging, overall complexity $ O (n \ sqrt n) $.

Positive Solutions practice for offline scanning line operation.

Each operation will be considered to join the left point, right point to delete.

It can be easily found that the addition operation together adjacent, then converted into a sequence of operations $ A_1 \ M_1 \ A_2 \ M_2 \ A_3 \ M_3 $ form.

Consideration has maintained the original take max legitimate operation, set $ s_i $ prefix $ A_i $ express and.

Max operation can take only established if $ M_ {i-1} + s_i-s_ {i-1} <M_i $.

Transposition available $ M_ {i-1} -s_ {i-1} <M_i-s_ {i} $, so long as the maintenance $ M_i-s_i $ monotonically increasing structure formed on it.

This thing can maintain the idea of ​​maintaining a monotonous stack segment tree.

 

B. travel plans

Sub-section is simple, but hard to think positive solutions.

Positive solutions probably take $ D $ is gcd $ k $ and right sides of all blocks within the link.

The obvious answer can only be a multiple of $ d $, and it might be all right to the edge and get rid of all $ k $ $ d $.

There is a case such that all sides of the link weights in the lower mold block Significance sum $ k $ $ $ 1.

However, only one circuit can be simply configured, such that any side of any even number of times after the link block (construction method is given solution to a problem in the DFS tree walk encountered a non-rotary side of the tree may be).

So constructed at a lower die $ k $ significance contribution of $ 2 $ loop $ C $ is feasible.

If $ k $ is odd, then we can continue to take $ u \ rightarrow v \ rightarrow u $ this path, so that the final answer is $ 0 $.

We need only consider the $ k $ even.

Now consider $ U \ whether there is a length of an even number (i.e., the lower die 2 $ $ $ $ 0 meaning) in the path between v $.

Because it already has circuit $ C $, if there is a path length is an even number, the answer surely is $ 0 $.

If not, then the answer can only be $ 1 $.

So, for each block of each parity Unicom staining (staining of course where standards are not adjacent flop), it is determined whether a bipartite graph it.

But there is a problem is that each given $ k $ is different, so there is no way to pre-treatment.

However, the even number is still noted here in addition to over $ k $ $ $ D after, that is to say the number of prime factors $ k $ $ $ than the original $ 2 $ Unicom GCD $ 2 $ blocks to be more .

Unicom so the original block in the right side of the parity after two different $ $ GCD is the same, so a direct addition is possible pretreatment.

 

C. Hack

Can be found directly minimal cut can guarantee each path must be cut, but can not guarantee the cut only once.

Hand cut play situation found more than once, is equivalent to the source sink formed respectively $ S $ / $ T $ set, satisfies a set of $ T $ $ memory back side S $ set, and then died.

Practice solution to a problem given that the establishment of the right side of each edge as $ inf $ reverse side, so the above case there will be augmenting path, so the above is not a legitimate cut.

Therefore, the minimum cut directly run on it.

Guess you like

Origin www.cnblogs.com/skyh/p/12204056.html