#include<stdio.h> #include<iostream> #include<stdlib.h> #include<vector> #include<list> #include<math.h> #include<algorithm> #include<string> #include<set> #include<queue> #define limit 65536 #define s 131072 #define inf 9223372036854775807ll #define iinf 2147483647 #define mp make_pair #define pb push_back #define rep(i,k,n) for(int i=k;i<n;i++) using namespace std; vector<pair<pair<int,int>,int> > cars; vector<pair<pair<int,int>,int> > carsend; int main(){ int t,n,w,x1,x2,y1,y2; scanf("%d",&t); rep(i,0,t){ int seg[s],out[limit]; cars.clear(); carsend.clear(); rep(i,0,s) seg[i]=0; bool ok=true; scanf("%d%d",&n,&w); rep(j,1,n+1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); cars.pb(mp(mp(x1,abs(y2-y1)),j)); } rep(j,1,n+1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); carsend.pb(mp(mp(x1,abs(y2-y1)),j)); } sort(cars.begin(),cars.end()); sort(carsend.begin(),carsend.end()); rep(j,0,n) out[carsend[j].second]=j; rep(j,0,n){ int k=limit+out[cars[j].second]; while(k>1){ if(k%2==0 && cars[j].first.second+seg[k+1]>w) ok=false; seg[k]=max(seg[k],cars[j].first.second); k/=2; } } if(ok) printf("TAK\n"); else printf("NIE\n"); } return 0; }
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 | #include<stdio.h> #include<iostream> #include<stdlib.h> #include<vector> #include<list> #include<math.h> #include<algorithm> #include<string> #include<set> #include<queue> #define limit 65536 #define s 131072 #define inf 9223372036854775807ll #define iinf 2147483647 #define mp make_pair #define pb push_back #define rep(i,k,n) for(int i=k;i<n;i++) using namespace std; vector<pair<pair<int,int>,int> > cars; vector<pair<pair<int,int>,int> > carsend; int main(){ int t,n,w,x1,x2,y1,y2; scanf("%d",&t); rep(i,0,t){ int seg[s],out[limit]; cars.clear(); carsend.clear(); rep(i,0,s) seg[i]=0; bool ok=true; scanf("%d%d",&n,&w); rep(j,1,n+1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); cars.pb(mp(mp(x1,abs(y2-y1)),j)); } rep(j,1,n+1){ scanf("%d%d%d%d",&x1,&y1,&x2,&y2); carsend.pb(mp(mp(x1,abs(y2-y1)),j)); } sort(cars.begin(),cars.end()); sort(carsend.begin(),carsend.end()); rep(j,0,n) out[carsend[j].second]=j; rep(j,0,n){ int k=limit+out[cars[j].second]; while(k>1){ if(k%2==0 && cars[j].first.second+seg[k+1]>w) ok=false; seg[k]=max(seg[k],cars[j].first.second); k/=2; } } if(ok) printf("TAK\n"); else printf("NIE\n"); } return 0; } |