3236: [Ahoi2013] Job time limit:100 Sec Memory limit:512 MB
submit:1393 solved:562
[Submit] [Status] [Discuss] Description
Input
Output
Sample Input3 4
1 2 2
1 2 1 3
1 2 1 1
1 3 1 3
2 3 2 3
Sample Output2 2
1 1
3 2
2 1HINT
n=100000,m=1000000
Source
by wangyisong1996 strengthening data
[Submit] [Status] [Discuss]
MO Team algorithm + tree-like array statistic answer
1#include <cmath>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <iostream>6#include <algorithm>7 8 using namespacestd;9 Ten /*SCANNER*/ One A #defineSiz 10000000 - -InlineCharGet_a (void) { the Static CharBuf[siz], *bit =buf; - - if(bit = = buf +siz) -Fread (bit = buf,1, Siz, stdin); + - return*bit++; + } A atInlineintGet_i (void) { -RegisterintRET =0; -RegisterintNeg =false; -Registerintbit =get_a (); - - for(; bit <'0'; bit =get_a ()) in if(bit = ='-') Neg ^=true; - to for(; bit >='0'; bit =get_a ()) +RET = RET *Ten+ Bit-'0'; - the returnNeg? -Ret:ret; * } $ Panax Notoginseng #defineMAXN 400005 - #defineMAXM 1000005 the + ints; A inttot; the intN, M; + intNUM[MAXN]; - intCNT[MAXN]; $ intTMP[MAXN]; $ intANS1[MAXM]; - intANS2[MAXM]; - intTREE1[MAXN]; the intTREE2[MAXN]; - Wuyi structQuery { the intL, R, a, B, id; - }QRY[MAXM]; Wu -InlineintcmpConst void*a,Const void*b) { AboutQuery *a = (query *) A; $Query *b = (query *) b; - if(a->l/s! = b->l/s) - returnA->l-b->l; - Else A returnA->r-b->R; + } the -InlinevoidAddint*t,intPintk) { $ for(; P <= tot; p + = p&-p) theT[P] + =K; the } the theInlineintAskint*t,intp) { - intRET =0; in for(p; p-= p&-p) theRET + =T[p]; the returnret; About } the theInlinevoidRemoveintt) { theAdd (tree1, T,-1); + if(--cnt[t] = =0) -Add (Tree2, T,-1); the }Bayi theInlinevoidInsertintt) { theAdd (tree1, T,1); - if(++cnt[t] = =1) -Add (tree2, T,1); the } the theSigned Main (void) { then =get_i (); -m =get_i (); thes =sqrt (n); the the for(inti =1; I <= N; ++i)94Num[i] = get_i (), tmp[++tot] =Num[i]; the the for(inti =1; I <= m; ++i) { theQry[i].id =i;98QRY[I].L =get_i (); AboutQRY[I].R =get_i (); -QRY[I].A =get_i ();101QRY[I].B =get_i ();102 }103 104 for(inti =1; I <= m; ++i) theTmp[++tot] =qry[i].a,106Tmp[++tot] =qry[i].b;107 108Sort (tmp +1, TMP +1+tot);109 thetot = unique (tmp +1, TMP +1+ tot)-tmp;111 the for(inti =1; I <= N; ++i)113Num[i] = lower_bound (tmp +1, tmp + tot, num[i])-tmp; the the for(inti =1; I <= m; ++i) { theQRY[I].A = Lower_bound (tmp +1, tmp + tot, QRY[I].A)-tmp;117qry[i].b = Lower_bound (tmp +1, tmp + tot, qry[i].b)-tmp;118 }119 - /*121 for (int i = 1; I <= n; ++i)122 printf ("%d", Num[i]);123 124 puts (""); the 126 for (int i = 1; I <= m; ++i)127 printf ("%d%d\n", QRY[I].A, qry[i].b); - */129 theQsort (Qry +1Msizeof(query), CMP);131 the intL =1, r =0;133 134 for(inti =1; I <= m; ++i) {135 while(L < QRY[I].L) Remove (num[l++]);136 while(L > QRY[I].L) Insert (num[--l]);137 while(R < QRY[I].R) Insert (num[++R]);138 while(R > Qry[i].r) Remove (num[r--]);139Ans1[qry[i].id] = Ask (Tree1, qry[i].b)-Ask (Tree1, QRY[I].A-1); $Ans2[qry[i].id] = Ask (Tree2, qry[i].b)-Ask (Tree2, QRY[I].A-1);141 }142 143 for(inti =1; I <= m; ++i)144printf"%d%d\n", Ans1[i], ans2[i]);145 146 //System ("pause");147}
@Author: Yousiki
Bzoj 3236: [Ahoi2013] Jobs