比赛 |
20120712 |
评测结果 |
WAWAAAWWWA |
题目名称 |
区间权最大 |
最终得分 |
50 |
用户昵称 |
czp |
运行时间 |
1.382 s |
代码语言 |
Pascal |
内存使用 |
10.08 MiB |
提交时间 |
2012-07-12 11:49:11 |
显示代码纯文本
var
max:array[1..800000] of longint;
a,y,z,b,x,ans,bh,next,v:array[1..200011] of longint;
i,j,m,n,mid,tp,l,vt:longint;
procedure sort(l,r:longint);
var i,j:longint;
begin
i:=l;
j:=r;
mid:=x[(l+r) div 2];
repeat
while x[i]<mid do inc(i);
while x[j]>mid do dec(j);
if i<=j then
begin
tp:=x[i];
x[i]:=x[j];
x[j]:=tp;
tp:=y[i];
y[i]:=y[j];
y[j]:=tp;
tp:=z[i];
z[i]:=z[j];
z[j]:=tp;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort(i,r);
if j>l then sort(l,j);
end;
procedure sort1(l,r:longint);
var i,j:longint;
begin
i:=l;
j:=r;
mid:=y[bh[(l+r) div 2]];
repeat
while y[bh[i]]<mid do inc(i);
while y[bh[j]]>mid do dec(j);
if i<=j then
begin
tp:=bh[i];
bh[i]:=bh[j];
bh[j]:=tp;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort1(i,r);
if j>l then sort1(l,j);
end;
procedure sort2(l,r:longint);
var i,j:longint;
begin
i:=l;
j:=r;
mid:=a[(l+r) div 2];
repeat
while a[i]<mid do inc(i);
while a[j]>mid do dec(j);
if i<=j then
begin
tp:=a[i];
a[i]:=a[j];
a[j]:=tp;
tp:=b[i];
b[i]:=b[j];
b[j]:=tp;
tp:=v[i];
v[i]:=v[j];
v[j]:=tp;
inc(i);
dec(j);
end;
until i>j;
if i<r then sort2(i,r);
if j>l then sort2(l,j);
end;
procedure insert(t,l,r,w,date:longint);
var mid:longint;
begin
if (w<l) or (r<w) then exit else
begin
if (l=w) and (r=w) then
max[t]:=date else
begin
mid:=(l+r) div 2;
insert(t<<1,l,mid,w,date);
insert(t<<1+1,mid+1,r,w,date);
max[t]:=max[t<<1];
if max[t<<1+1]>max[t] then max[t]:=max[t<<1+1];
end;
end;
end;
function get(t,l,r,x,y:longint):longint;
var mid,v1,v2:longint;
begin
if (y<l) or (x>r) then exit else
begin
if (x<=l) and (r<=y) then
get:=max[t] else
begin
mid:=(l+r) div 2;
v1:=get(t<<1,l,mid,x,y);
v2:=get(t<<1+1,mid+1,r,x,y);
if v1<v2 then v1:=v2;
get:=v1;
end;
end;
end;
function find(x:longint):longint;
var s,t,mid:longint;
begin
s:=1;t:=n;
while s<t do
begin
mid:=(s+t) div 2;
if x>y[bh[mid]] then s:=mid+1 else t:=mid;
end;
find:=s;
end;
begin
assign(input,'max.in');reset(input);
assign(output,'max.out');rewrite(output);
readln(n,m);
for i:=1 to n do readln(x[i],y[i],z[i]);
inc(n);
x[n]:=1;y[n]:=maxlongint;z[n]:=0;
for i:=1 to m do readln(a[i],b[i]);
sort(1,n);
for i:=1 to n do bh[i]:=i;
for i:=1 to m do v[i]:=i;
sort2(1,m);
sort1(1,n);
for i:=1 to n do begin next[bh[i]]:=i;insert(1,1,n,i,z[bh[i]]);end;
j:=1;
for i:=1 to m do
begin
while x[j]<a[i] do
begin
insert(1,1,n,next[j],0);
inc(j);
end;
l:=find(b[i]);
if (y[bh[l]]=b[i]) then l:=find(b[i]+1);
dec(l);
vt:=get(1,1,n,1,l);
ans[v[i]]:=vt;
end;
for i:=1 to m do writeln(ans[i]);
close(input);close(output);
end.