Test instructions
N (10^5) guests come to the store to give the time and the price of the goods to the salesperson every W minutes to sleep if the guest comes when she wakes her up when she sleeps but does not buy things to buy things the number of guests to purchase is 1, 2, 3, 1, 2, 3 ... The average price of the thing to sell when the loop asks how big is W
Ideas:
It is easy to think of the time that the guests are pressed and then calculate their interval w must be one of those intervals, that is, the enumeration of N W.
If we sort the interval, then for someone who buys something W in front of W, we can maintain a sequence to constantly update ans when we enumerate W.
Assume that the known sequence A1 A2 A3 .... Ax's ans and so on the new w should insert B into that could be A1 A2 b a3 ... ax sequence then we find that everyone who buys things from B has changed, but the relative position of people from A3 to Ax has not changed, so we can This computes the value of the new sequence newval = A1 (start from 1) + B (start from 3) + A3 (start from 1) here only one of the B's may be the same for the others so for each point in the sequence we expect fast Know that this sequence start from 1, 2, 3 of the 3 values this can be done using the segment tree within the Logn
Code:
#include <cstdio> #include <iostream> #include <cstring> #include <string> #include < algorithm> #include <map> #include <set> #include <vector> #include <queue> #include < cstdlib> #include <ctime> #include <cmath>using namespace std;typedef long long LL; #define N 100010#define L (x) (x<<1) #define R (x) ((x<<1) | |) int t,n,w;double ans;struct input{int id,p,t;} G[n];bool cmp1 (Input f1,input f2) {return f1.t<f2.t;} BOOL CMP2 (Input f1,input f2) {if (f1.t!=f2.t) return F1.t<f2.t;return f1.id<f2.id;} struct node{ll sum[4];} F[n<<2];int leaf[n],cnt;void init (int l,int r,int i) {for (int j=0;j<4;j++) f[i].sum[j]=0;if (l==r) {leaf[cnt++] =i;return;} int mid= ((l+r) >>1); Init (l,mid,l (i)); Init (Mid+1,r,r (i)); void update (int i) {int u=leaf[g[i].id];f[u].sum[0]=1;for (int j=1;j<4;j++) f[u].sum[j]=g[i].p*j;do{u>>=1; int left=f[l (U)].sum[0];f[u].sum[0]=left+f[r (u)].sum[0];for (int j=1;j<4;j++) {int tmp= (j+left)%3;if (!tmp) tmp=3; f[u].sum[j]=f[l (U)].sum[j]+f[r (u)].sum[tmp];} while (u!=1);} int main () {scanf ("%d", &t), while (t--) {scanf ("%d", &n), for (int i=1;i<=n;i++) scanf ("%d", &G[I].P); int i=1;i<=n;i++) scanf ("%d", &g[i].t), if (n==1) {printf ("%.6f%.6f\n", (double) (g[1].t), (double) (G[1].P)); Continue;} Sort (G+1,G+N+1,CMP1); for (int i=n;i>=1;i--) {g[i].t-=g[i-1].t;g[i].id=i;} Sort (G+1,G+N+1,CMP2); Ans=-1;cnt=1;init (1,n,1); g[n+1].t=-1;for (int i=1;i<=n;i++) {update (i); if (g[i].t!=g[i+1]. T) {double tmp= (double) (f[1].sum[1])/f[1].sum[0];if (Tmp>ans) {ans=tmp;w=g[i].t;}} printf ("%.6f%.6f\n", (Double) (W), ans); return 0;}
ZOJ 3606 Lazy Salesgirl