Qaq is a set of water problems.
Then the sad story is that the teacher set the time to four and a half hours
I wrote something else for half an hour because I wanted to debut spent maths.
Then I didn't finish the question! Qaq
Or we could get a little more points for the third question.
I thought of the positive solutions to all the problems in the morning.
The only drawback is that I think the third question is O (n^4*300) is the time complexity
In fact, there will be only n intervals after the discretization interval, and the time complexity is O (n^5) qaq
First of all, the
First Battle conic
Obviously given your function, A*x+b*y+c*x*y is relatively equivalent to X, Y.
Because of the randomness of the input of the topic, it is obvious that the Kd_tree query can be done by maintaining the line tree on the segment tree.
Notice that x, Y is a positive integer, and that the range of × is range, so we can use the segment tree to maintain the maximum value of Y to complete a query like Kd_tree.
Time complexity slightly somewhat metaphysical, heard random data under O (nlog^2n)?
#include <cstdio> #include <cstring> #include <iostream> #include <cstdlib> #include < Algorithm>using namespace Std;typedef long long ll;const int maxn=100010;const LL oo=1ll<<60;int n,m,x,p,v,le, Re;int a,b,c;int a[maxn];int mx[maxn<<2];int mn[maxn<<2];bool vis[maxn<<2]; LL ans;int Get_r () {x= (1ll*100000005*x+20150609)%998244353;return x/100;} void read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ') Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();} void build (int o,int l,int R) {if (l==r) {Mx[o]=mn[o]=a[l];return;} int mid= (L+R) >>1;build (O<<1,l,mid); build (O<<1|1,mid+1,r); Mx[o]=max (mx[o<<1],mx[o< <1|1]); Mn[o]=min (mn[o<<1],mn[o<<1|1]);} void down (int o,int l,int r) {int mn,mx;vis[l]^=1;vis[r]^=1; MN=MN[L]; MX=MX[L];MX[L]=100000-MN;MN[L]=100000-MX; MN=MN[R]; Mx=mx[r];mx[r]=100000-mn;mn[r]=100000-mx;vis[o]=false;} void UPD (int o,int l,int R) {if (l==r) {Mx[o]=mn[o]=v;return;} int mid=(l+r) >>1;int l= (o<<1), r= (l|1), if (Vis[o]) down (o,l,r), if (P<=mid) upd (L,l,mid), Else upd (r,mid+1,r); MX [O]=max (Mx[l],mx[r]); Mn[o]=min (Mn[l],mn[r]);} void Modify (int o,int L,int R) {if (l>=le&&r<=re) {Vis[o]^=1;int Mn=mn[o],mx=mx[o];mx[o]=100000-mn;mn[o] =100000-mx;return;} int mid= (L+R) >>1;int l= (o<<1), r= (l|1), if (Vis[o]) down (o,l,r), if (re<=mid) modify (L,l,mid), else if (le >mid) Modify (r,mid+1,r), else Modify (L,l,mid), modify (R,mid+1,r); Mx[o]=max (Mx[l],mx[r]); Mn[o]=min (Mn[l],mn[r]);} LL Get_ans (int o,int l,int R) {int tmp=mx[o]; LL k= (a+1ll*c*tmp); return k*r+1ll*b*tmp;} void Kd_ask (int o,int l,int R) {if (l==r) {Ans=max (ans,1ll*a*l+1ll*b*mn[o]+1ll*c*l*mn[o]); return;} int mid= (L+R) >>1;int l= (o<<1), r= (l|1), if (Vis[o]) down (O,L,R); LL D1=get_ans (L,l,mid); LL D2=get_ans (R,MID+1,R); if (D1>D2) {if (D1>ans) kd_ask (L,l,mid); if (D2>ans) kd_ask (r,mid+1,r);} Else{if (D2>ans) kd_ask (r,mid+1,r), if (D1>ans) kd_ask (l,l,mid);} return;} void Ask (int o,int l,int R) {if (l>=Le&&r<=re) {kd_ask (o,l,r); return;} int mid= (L+R) >>1;int l= (o<<1), r= (l|1), if (Vis[o]) down (o,l,r), if (Re<=mid) Ask (L,l,mid), else if (le> Mid) Ask (R,MID+1,R); else ask (L,l,mid), ask (R,mid+1,r);} int main () {freopen ("conic.in", "R", stdin), Freopen ("Conic.out", "w", stdout); Read (n); read (m); Read (x); for (int i=1;i <=n;++i) A[i]=get_r ()%100001;build (1,1,n), while (m--) {char Ch=getchar (), while (ch< '! ') Ch=getchar (); if (ch== ' C ') {P=get_r ()%n+1;v=get_r ()%100001; UPD (1,1,n);} else if (ch== ' R ') {Le=get_r ()%n+1;re=get_r ()%n+1;if (le>re) swap (le,re); modify (1,1,n);} Else{read (A); Read (B), read (C), Ans=-oo;le=get_r ()%n+1;re=get_r ()%n+1;if (le>re) Swap (le,re), ask (1,1,n);p rintf (" %lld\n ", ans);}} return 0;}
Second question
Apparently 30 points are white for state compression or plug DP
Before there is a topic is the minimum cut I use the plug DP cheated 90 points, then consider this problem can be solved with network flow
It is not difficult to find that if two B can be eliminated, the parity of the two B lines must be different
This has the properties of a binary graph for B, but it also takes into account the influence of a.
And each of our streams is going to represent a b-a-b solution.
After careful consideration, you can get the following map:
Our S-to-lines are even-numbered B-sides, and the number of rows is an odd B-to-t edge.
For an even number of rows, we have a four-way edge
For each A-break current limit
Then the number of rows is even, a to the left and right two direction of the B edge
The number of rows is odd for a to the top and bottom of the B edge in two directions
It is not difficult to find that each flow represents a viable l
Then the maximum flow can be, because the edge of the right is 1, so the network flow running fast
QAQ exam When the guilty also wrote a plug DP pair Pat Qaq
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < Cstdlib> #include <queue>using namespace std;const int Maxn=500010;const int Oo=0x7fffffff;int n,m,s,t,ans;int C[510][510];int idx[510][510],tot=0;int h[maxn],cnt=1;int vis[maxn];struct edge{int to,next,w;} g[8000010];queue<int>q;void Add (int x,int y,int z) {++cnt; G[cnt].to=y; G[CNT].NEXT=H[X]; g[cnt].w=z;h[x]=cnt;++cnt; G[cnt].to=x; G[cnt].next=h[y]; g[cnt].w=0;h[y]=cnt;} void read (int &num) {Num=0;char Ch=getchar (); while (ch< '! ') Ch=getchar (); while (ch>= ' 0 ' &&ch<= ' 9 ') num=num*10+ch-' 0 ', Ch=getchar ();} BOOL BFS () {Q.push (S); for (int i=s;i<=t;++i) Vis[i]=-1;vis[s]=0;while (! Q.empty ()) {int U=q.front (); Q.pop (); for (int i=h[u];i;i=g[i].next) {int v=g[i].to;if (vis[v]==-1&&g[i].w>0) {vis[v]=vis[u]+1; Q.push (v);}} return vis[t]!=-1;} int DFS (int x,int f) {if (x==t| | f==0) return f;int w,used=0;for (int i=h[x];i;i=g[i].next) {if (vis[g[i].to]==vis[x]+1) {W=f-used;w=dfs (G[i]. To,min (W,G[I].W)); G[i].w-=w; G[i^1].w+=w;used+=w;if (used==f) return used;}} if (!used) Vis[x]=-1;return used;} void Dinic () {Ans=0;while (BFS ()) Ans+=dfs (S,oo);} int main () {freopen ("molecule.in", "R", stdin), Freopen ("Molecule.out", "w", stdout); Read (n); read (m); for (int i=1;i< =n;++i) for (int j=1;j<=m;++j) read (C[i][j]), for (int. i=1;i<=n;++i) {for (int j=1;j<=m;++j) {if (c[i][j]==0) Continue;idx[i][j]=++tot;if (C[i][j]==1) ++tot;}} s=0; t=tot+1;for (int i=1;i<=n;++i) {for (int j=1;j<=m;++j) {if (c[i][j]==0) continue;if (i&1) {if (c[i][j]==2) {Add ( s,idx[i][j],1); if (j-1>=1&&c[i][j-1]==1) Add (idx[i][j],idx[i][j-1],1); if (j+1<=m&&c[i][j+1] ==1) Add (idx[i][j],idx[i][j+1],1), if (i-1>=1&&c[i-1][j]==1) Add (idx[i][j],idx[i-1][j],1), if (i+1<=n &&c[i+1][j]==1) Add (idx[i][j],idx[i+1][j],1);} Else{add (idx[i][j],idx[i][j]+1,1); if (i-1>=1&&c[i-1][j]==2) Add (idx[i][j]+1,idx[i-1][j],1); if (i+1< =n&&c[i+1][j]==2) Add (idx[i][j]+1,idx[i+1][j],1);}} Else{if (c[i][j]==2) Add (idx[i][j],t,1); Else{add (idx[i][j],idx[i][j]+1,1); if (j+1<=m&&c[i][j+1]==2) Add (idx[i][j]+1,idx[i][j+1 ],1); if (j-1>=1&&c[i][j-1]==2) Add (idx[i][j]+1,idx[i][j-1],1);}}} Dinic ();p rintf ("%d\n", ans); return 0;}
Third question
We note that I cannot calculate the probability of the I-ratio j alone and pack
Because the probabilities will affect each other.
So we might as well enumerate each point in that interval.
It's not hard to find other points. There are only three cases of this point.
Win,lose,in (in the interval)
It is advisable to set F (i,j) to indicate that I have a point that is stronger than the current point and has J points and the current point in an interval.
When it's time to move, you can pack it.
Then we noticed that for a status F (i,j), the current point rank could be i+1->i+j+1
and the probability is F (i,j) *p/(j+1) P is the probability of the current point in this interval
Then contribute to ans (i) on it.
Time complexity O (n^5), when the exam time is not enough not to recall (now seems to be OJ card constant?)
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include < cstdlib> #include <cmath> #define EPS 1e-10#define fastcall __attribute__ ((Optimize ("-o3")) #define IL __ inline__ __attribute__ ((always_inline)) using namespace Std;const int maxn=162;int n,cnt=0;int d[maxn];struct OP{int L,R ;} C[MAXN];d ouble G[MAXN];d ouble f[82][82];fastcall IL int get_pos (int v) {int L=1,r=cnt;while (l<r) {int mid=l+ ((r-l+1) >>1); if (d[mid]<=v) L=mid;else r=mid-1;} return L;} Double Min (double l,double R) {return l<r? L:r;} Double Max (double l,double R) {return l>r? L:r;} Fastcall IL double get_win (int l,int r,int i) {if (C[i]. L>=L) return 0;return (Double) (Min (c[i). r,l)-c[i]. L)/(C[i]. R-c[i]. L);} Fastcall IL double get_lose (int l,int r,int i) {if (C[i]. R<=R) return 0;return (Double) (C[i]. R-max (C[i]. L,R))/(C[i]. R-c[i]. L);} Fastcall IL double get_in (int l,int r,int i) {if (C[i]. l>=r| | C[i]. R<=L) return 0;return (Double) (Min (c[i). R,r)-max (C[i]. l,l))/(C[i]. RC[i]. L);} Fastcall IL void get_f (int l,int r,int now) {double p= (double) (r-l)/(C[now]. R-c[now]. L); memset (F,0,sizeof (f)); f[0][0]=1;for (int i=1;i<=n;++i) {if (I==now) continue;double P1=get_win (l,r,i);d ouble p2 =get_lose (l,r,i);d ouble p3=get_in (l,r,i); for (int. j=i;j>=0;--j) {for (int k=i-j;k>=0;--k) {f[j][k]=f[j][k]*p1; if (j>=1) f[j][k]=f[j][k]+f[j-1][k]*p2;if (k>=1) F[j][k]=f[j][k]+f[j][k-1]*p3;}}} for (int i=0;i<n;++i) {for (int j=0;j<n-i;++j) {double tmp=f[i][j];if (fabs (TMP) <eps) continue;tmp=tmp*p/(j+1) ; for (int k=0;k<=j;++k) {g[i+k]=g[i+k]+tmp;}}} return;} int main () {freopen ("gg.in", "R", stdin), Freopen ("Gg.out", "w", stdout), scanf ("%d", &n), for (int i=1;i<=n;++i) { scanf ("%d%d", &c[i]. L,&c[i]. R);d [++cnt]=c[i]. L;d[++cnt]=c[i]. R;} Sort (d+1,d+cnt+1); Cnt=unique (d+1,d+cnt+1)-d-1;for (int i=1;i<=n;++i) {memset (g,0,sizeof (g)); int L=get_pos (C[i]. L), R=get_pos (C[i]. R), for (int j=l;j<r;++j) Get_f (D[j],d[j+1],i), and for (int j=0;j<n;++j) printf ("%.6lf", G[j]);p rintf ("\ n");} return 0;}
There's nothing to say about the last two days Qaq
are very basic things, push a push can be written
Basically, it's a, qaq.
The probability is still weak, if the morning write right, then AK
There is time to fill the probability.
6.19 Exam Revision + Summary