标签:ast NPU turn cout size sig sys sse first
1 #define IOS ios_base::sync_with_stdio(0); cin.tie(0); 2 #include <cstdio>//sprintf islower isupper 3 #include <cstdlib>//malloc exit strcat itoa system("cls") 4 #include <iostream>//pair 5 #include <fstream>//freopen("C:\\Users\\13606\\Desktop\\Input.txt","r",stdin); 6 #include <bitset> 7 //#include <map> 8 //#include<unordered_map> 9 #include <vector> 10 #include <stack> 11 #include <set> 12 #include <string.h>//strstr substr strcat 13 #include <string> 14 #include <time.h>// srand(((unsigned)time(NULL))); Seed n=rand()%10 - 0~9; 15 #include <cmath> 16 #include <deque> 17 #include <queue>//priority_queue<int, vector<int>, greater<int> > q;//less 18 #include <vector>//emplace_back 19 //#include <math.h> 20 #include <cassert> 21 #include <iomanip> 22 //#include <windows.h>//reverse(a,a+len);// ~ ! ~ ! floor 23 #include <algorithm>//sort + unique : sz=unique(b+1,b+n+1)-(b+1);+nth_element(first, nth, last, compare) 24 using namespace std;//next_permutation(a+1,a+1+n);//prev_permutation 25 //****************** 26 clock_t __START,__END; 27 double __TOTALTIME; 28 void _MS(){__START=clock();} 29 void _ME(){__END=clock();__TOTALTIME=(double)(__END-__START)/CLOCKS_PER_SEC;cout<<"Time: "<<__TOTALTIME<<" s"<<endl;} 30 //*********************** 31 #define rint register int 32 #define fo(a,b,c) for(rint a=b;a<=c;++a) 33 #define fr(a,b,c) for(rint a=b;a>=c;--a) 34 #define mem(a,b) memset(a,b,sizeof(a)) 35 #define pr printf 36 #define sc scanf 37 #define ls rt<<1 38 #define rs rt<<1|1 39 typedef pair<int,int> PII; 40 typedef vector<int> VI; 41 typedef long long ll; 42 const double E=2.718281828; 43 const double PI=acos(-1.0);// 44 const ll INF=(1LL<<60); 45 const int inf=(1<<30); 46 const double ESP=1e-9; 47 const int mod=(int)1e9+7; 48 const int N=(int)1e6+10; 49 50 PII a[N]; 51 int ans[N]; 52 int c[N],maxn,now; 53 int lowbit(int n){return n&(-n);} 54 void add(int i,int t) 55 { 56 while(i<=maxn) 57 { 58 c[i]+=t; 59 i+=lowbit(i); 60 } 61 } 62 int Sum(int i) 63 { 64 int sum=0; 65 while(i) 66 { 67 sum+=c[i]; 68 i-=lowbit(i); 69 } 70 return sum; 71 } 72 struct node 73 { 74 int l,r,k,id; 75 }q[N],temp[N]; 76 77 void solve(int l,int r,int ql,int qr,int n) 78 { 79 int L=ql,R=qr,mid=l+r>>1; 80 81 if(l==r) 82 { 83 // pr("1\n"); 84 for(int i=ql;i<=qr;++i)ans[q[i].id]=l; 85 return; 86 } 87 88 while(a[now+1].first<=mid&&now+1<=n)++now,add(a[now].second,1);//这边保证了一个位置最大经过3次; 89 while(now&&a[now].first>mid)add(a[now].second,-1),--now;// 全清空会TLE; 90 91 for(int i=ql;i<=qr;++i) 92 { 93 int res=Sum(q[i].r)-Sum(q[i].l-1); 94 if(res>=q[i].k)temp[L++]=q[i]; 95 else temp[R--]=q[i]; 96 } 97 for(int i=ql;i<=qr;++i) 98 q[i]=temp[i]; 99 if(L>ql)solve(l,mid,ql,L-1,n); 100 if(R<qr)solve(mid+1,r,R+1,qr,n); 101 } 102 103 int main() 104 { 105 int T; 106 sc("%d",&T); 107 while(T--) 108 { 109 int n,m; 110 sc("%d%d",&n,&m); 111 for(int i=1;i<=n;++i)sc("%d",&a[i].first),a[i].second=i,c[i]=0; 112 maxn=n; 113 now=0; 114 for(int i=1;i<=m;++i) 115 sc("%d%d%d",&q[i].l,&q[i].r,&q[i].k),q[i].id=i; 116 sort(a+1,a+1+n); 117 solve(-inf,inf,1,m,n); 118 for(int i=1;i<=m;++i) 119 pr("%d\n",ans[i]); 120 } 121 return 0; 122 } 123 124 /**************************************************************************************/
标签:ast NPU turn cout size sig sys sse first
原文地址:https://www.cnblogs.com/--HPY-7m/p/11913250.html