#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <map> #include <set> #include <cassert> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; const ll mod=1000000007; ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} // head #include "krazki.h" #include "message.h" const int N=2510000; int n,T,block,myid; void output(int id,ll v) { if (id>=0&&id<T) { PutLL(id,v); Send(id); } } ll a[N]; int main() { n=PipeHeight(),T=NumberOfNodes(),block=(n+T-1)/T,myid=MyNodeId(); int l=block*myid+1,r=min(block*(myid+1),n); int m=r-l+1; rep(i,1,m+1) a[i]=HoleDiameter(i+l-1); // deliver prefix min rep(i,2,m+1) a[i]=min(a[i],a[i-1]); ll ph=1ll<<60; if (myid!=0) { Receive(myid-1); ph=min(ph,GetLL(myid-1)); } output(myid+1,min(ph,a[m])); // printf("%d %lld\n",myid,ph); //process ll p=0,q=NumberOfDiscs(); if (myid==T-1) { p=q; } else { Receive(myid+1); p=GetLL(myid+1); } // printf("%d %lld\n",myid,p); if (p==0) { output(myid-1,0); return 0; } ll v=DiscDiameter(q-p+1); per(i,1,m+1) { if (myid!=0&&v>ph) { output(myid-1,p); return 0; } while (i&&a[i]<v) i--; if (i==0) break; if (p==1) { printf("%d\n",l+i-1); output(myid-1,0); return 0; } --p; v=DiscDiameter(q-p+1); } if (myid==0) puts("0"); else output(myid-1,p); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <map> #include <set> #include <cassert> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) typedef vector<int> VI; typedef long long ll; typedef pair<int,int> PII; const ll mod=1000000007; ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} // head #include "krazki.h" #include "message.h" const int N=2510000; int n,T,block,myid; void output(int id,ll v) { if (id>=0&&id<T) { PutLL(id,v); Send(id); } } ll a[N]; int main() { n=PipeHeight(),T=NumberOfNodes(),block=(n+T-1)/T,myid=MyNodeId(); int l=block*myid+1,r=min(block*(myid+1),n); int m=r-l+1; rep(i,1,m+1) a[i]=HoleDiameter(i+l-1); // deliver prefix min rep(i,2,m+1) a[i]=min(a[i],a[i-1]); ll ph=1ll<<60; if (myid!=0) { Receive(myid-1); ph=min(ph,GetLL(myid-1)); } output(myid+1,min(ph,a[m])); // printf("%d %lld\n",myid,ph); //process ll p=0,q=NumberOfDiscs(); if (myid==T-1) { p=q; } else { Receive(myid+1); p=GetLL(myid+1); } // printf("%d %lld\n",myid,p); if (p==0) { output(myid-1,0); return 0; } ll v=DiscDiameter(q-p+1); per(i,1,m+1) { if (myid!=0&&v>ph) { output(myid-1,p); return 0; } while (i&&a[i]<v) i--; if (i==0) break; if (p==1) { printf("%d\n",l+i-1); output(myid-1,0); return 0; } --p; v=DiscDiameter(q-p+1); } if (myid==0) puts("0"); else output(myid-1,p); } |