D - Data Mining - Gym 100496 D - 오프라인 처리 + 트 리 배열 + 이산 화
// +
// 【 1,N】 a , , b
//Gym 100496D [a,b] ,b , 。
// 【 】 , a, a 1 , a , a
, [a,b] , ! , , , , ,
, ,, , , ( )。。 ... ,
, 。
vis ( 10^9, ) [N], 【a,b】, b-for a , 【 】 ;
, , 【 】 for , [a,b] 【b 】 b 【 】( ), 【 】
get_sum(【b 】)
#include <cstdio>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <queue>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define inf 0x7f7f7f7f;
const int maxn=100000*2+5;
int n,m;
struct node
{
int x,num; //
} A[maxn];
struct edge
{
int x,y,num;
} tm[maxn];
int cmp(node a,node b)
{
return a.x<b.x; // ,
}
int posi[maxn];
int vis[maxn];
int max(int a,int b )
{
if (a<b)return b;return a;
}
int tree[maxn];
inline int lowbit(int x)
{
return x&-x;
}
void add(int x,int value)
{
for (int i=x;i<=n;i=i+lowbit(i))
{
tree[i]+=value;
}
}
int get(int x)
{
int sum=0;
for (int i=x;i;i-=lowbit(i))
{
sum+=tree[i];
}
return sum;
}
int cmp2(edge a,edge b)
{
if (a.x!=b.x)
return a.x>b.x;
else
return a.y<b.y;
}
int ans[maxn];
int main()
{
freopen( "data.in","r",stdin ); //scanf 1.txt
freopen( "data.out","w",stdout ); //printf 1.tx
int i,a,b,j;
cin>>n;
for (i=1;i<=n;i++)
{
scanf("%d",&A[i].x);
A[i].num=i;
}
sort(A+1,A+1+n,cmp); //
int ok=0;
for (i=1;i<=n;i++) // ,
{
ok++;
if (A[i].x==A[i-1].x) // ,
{
ok--;
posi[A[i].num]=ok;
}
else
posi[A[i].num]=ok;
}
cin>>m;
int maxx=0;
for (i=1;i<=m;i++)
{
scanf("%d%d",&tm[i].x,&tm[i].y);
tm[i].y+=tm[i].x-1; // 【a b 】 【 a+b-1 】
tm[i].num=i; //
maxx=max(maxx,tm[i].y); //
}
sort(tm+1,tm+1+m,cmp2); // , 【1,3】 【2,4】 【2,4】, 【1,3】 , ;
int mark_l=maxx;
vis[ posi[mark_l] ]=mark_l; // 。
add(mark_l,1);
for (i=1;i<=m;i++)
{
a=tm[i].x;
b=tm[i].y;
if (a<mark_l) // a>=mark_l , 。
{
for (j=mark_l-1;j>=a;j--) // 【 mark_l a】
{
if (vis[ posi[j] ]==0) //
{
vis[ posi[j] ]=j;
add(j,1);
}
else
{
int t=vis[ posi[j] ];
add(t,-1);
vis[ posi[j] ]=j;
add(j,1);
}
}
}
// cout<<get(vis[posi[b]])<<endl;
ans[tm[i].num]=get( vis[posi[b]]);
mark_l=a;
}
for (i=1;i<=m;i++)
{
printf("%d
",ans[i]);
}
return 0;
}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.