# bzoj3236: [Ahoi2013]作业

## 3236: [Ahoi2013]作业

Time Limit: 100 Sec  Memory Limit: 512 MB
Submit: 1423  Solved: 572
[Submit][Status][Discuss]

3 4
1 2 2
1 2 1 3
1 2 1 1
1 3 1 3
2 3 2 3

2 2
1 1
3 2
2 1

## HINT

N=100000,M=1000000

pascal毫无悬念的T了……上C艹就过了……

 1 #include<iostream>
2 #include<set>
3 #include<map>
4 #include<cstdio>
5 #include<cstring>
6 #include<cstdlib>
7 #include<algorithm>
8 #include<cmath>
9 using namespace std;
10 const int maxn=100086;
12 {
13     int x=0,f=1;char ch=getchar();
14     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
15     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
16     return x*f;
17 }
18 struct data{int l,r,a,b,bel,id;} op[10*maxn];
19 int num[maxn],a[maxn],ans[maxn*10][2],c[2][maxn];
20 int size,n,m;
21 bool cmp(data x,data y)
22 {
23     if(x.bel!=y.bel)return x.bel<y.bel;else return x.r<y.r;
24 }
25 void add(int x,int ps,int dd)
26 {
27     for(int i=ps;i<=n;i+=i&(-i))c[x][i]+=dd;
28 }
30 {
31     int sum=0;
32     for(int i=ps;i;i-=i&(-i))sum+=c[x][i];
33     return sum;
34 }
35 void ins(int x)
36 {
39 }
40 void del(int x)
41 {
44 }
45 void solve()
46 {
47     int l=1,r=0;
48     for(int i=1;i<=m;i++)
49     {
50         while(r<op[i].r)ins(a[++r]);
51         while(l>op[i].l)ins(a[--l]);
52         while(r>op[i].r)del(a[r--]);
53         while(l<op[i].l)del(a[l++]);
56     }
57 }
58 int main()
59 {
62     size=sqrt(n);
63     for(int i=1;i<=m;i++)
64     {
66         op[i].id=i;op[i].bel=(op[i].l-1)/size+1;
67     }
68     sort(op+1,op+m+1,cmp);
69     solve();
70     for(int i=1;i<=m;i++)printf("%d %d\n",ans[i][0],ans[i][1]);
71     return 0;
72 }
View Code

pascal版本果断T掉了

 1 program j01;
2 type xx=record l,r,a,b,bel,id:longint; end;
3 var op:array[0..1000086]of xx;
4     num,a:array[0..100086]of longint;
5     c:array[0..1,0..100086]of longint;
6     ans:array[0..1000086,0..1]of longint;
7     n,m,size,i:longint;
8
9 function cmp(x,y:xx):boolean;
10 begin
11   if x.bel<>y.bel then exit(x.bel<y.bel)
12     else exit(x.r<y.r);
13 end;
14
15 procedure qsort(l,r:longint);
16 var i,j:longint;x,y:xx;
17 begin
18   i:=l;j:=r;x:=op[(i+j) div 2];
19   repeat
20     while cmp(op[i],x) do inc(i);
21     while cmp(x,op[j]) do dec(j);
22     if i<=j then
23     begin
24       y:=op[i];op[i]:=op[j];op[j]:=y;
25       inc(i);dec(j);
26     end;
27   until i>j;
28   if i<r then qsort(i,r);
29   if l<j then qsort(l,j);
30 end;
31
33 begin
34   while i<=n do
35   begin
36     inc(c[x,i],dd);
37     i:=i+(i and(-i));
38   end;
39 end;
40
42 begin
44   while i>0 do
45   begin
47     i:=i-(i and(-i));
48   end;
49 end;
50
51 procedure ins(x:longint);
52 begin
55 end;
56
57 procedure del(x:longint);
58 begin
61 end;
62
63 procedure solve;
64 var i,l,r:longint;
65 begin
66   fillchar(num,sizeof(num),0);
67   l:=1;r:=0;
68   for i:=1 to m do
69   begin
70     while r<op[i].r do begin inc(r);ins(a[r]); end;
71     while l>op[i].l do begin dec(l);ins(a[l]); end;
72     while r>op[i].r do begin del(a[r]);dec(r); end;
73     while l<op[i].l do begin del(a[l]);inc(l); end;
76   end;
77 end;
78
79 begin
81   for i:=1 to n do read(a[i]);
82   size:=trunc(sqrt(n));
83   for i:=1 to m do
84   begin
92 end.