hdu 4027 Can you answer these queries? The 36th ACM/ICPC Asia Regional Shanghai Site
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
경 기 를 할 때 반드시 업데이트 해 야 한 다 는 것 을 알 았 지만 어떻게 업데이트 해 야 할 지 생각 하지 못 해 한 번 에 업 데 이 트 했 습 니 다. 과감 한 TLE, 사실은 만 알 면 됩 니 다.int 64 범위 내의 수 는 최대 8 번 을 취하 면 1 또는 0 에 이 를 수 있 습 니 다. 그러면 생각 이 있 습 니 다. 즉, 모든 수의 i 번 뿌리 를 미리 구 하 는 것 입 니 다. 나 무 를 만 드 는 과정 에서 직접 업데이트 하고 업데이트 하 는 것 입 니 다. 그러면 매번 업데이트 할 때마다 뿌리 를 얻 는 횟수 만 업데이트 하면 됩 니 다.
코드 는 다음 과 같 습 니 다:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
const int maxx=100002;
struct Tree
{
__int64 sum[9];
int cnt;
int col;
};
__int64 da[maxx],mx;
int lim;
Tree tree[maxx<<2];
void pushUp(int rt)
{
for (int i=0;i<=lim;i++)
{
tree[rt].sum[i]=tree[rt<<1].sum[i]+tree[rt<<1|1].sum[i];
}
}
void pushDown(int rt)
{
if (tree[rt].col!=0)
{
tree[rt<<1].cnt+=tree[rt].col;
tree[rt<<1].col+=tree[rt].col;
tree[rt<<1|1].cnt+=tree[rt].col;
tree[rt<<1|1].col+=tree[rt].col;
tree[rt].col=0;
}
}
void update(int L,int R,int l,int r,int rt)
{
if (L<=l && r<=R)
{
tree[rt].col+=1;
tree[rt].cnt+=1;
return;
}
pushDown(rt);
int m=(l+r)>>1;
if (L<=m)update(L,R,lson);
if (R>m)update(L,R,rson);
}
void build(int l,int r,int rt)
{
tree[rt].cnt=tree[rt].col=0;
if (l==r)
{
tree[rt].sum[0]=da[l];
for (int i=1;i<=lim;i++)
{
tree[rt].sum[i]=(__int64)sqrt((double)tree[rt].sum[i-1]);
}
return;
}
int m=(l+r)>>1;
build(lson);
build(rson);
pushUp(rt);
}
__int64 query(int L,int R,int l,int r,int rt)
{
if (L<=l && r<=R)
{
if (tree[rt].cnt>lim)tree[rt].cnt=lim;
if (tree[rt].cnt==lim || l==r)
{
return tree[rt].sum[tree[rt].cnt];
}
pushDown(rt);
int m=(l+r)>>1;
return query(L,R,lson)+query(L,R,rson);
}
pushDown(rt);
int m=(l+r)>>1;
__int64 ret=0;
if (L<=m) ret+=query(L,R,lson);
if (R>m) ret+=query(L,R,rson);
return ret;
}
int main()
{
int n,o,cas=1;
while (scanf("%d",&n)!=EOF)
{
mx=0;
int i;
printf("Case #%d:
",cas++);
for (i=1;i<=n;i++)
{
scanf("%I64d",&da[i]);
if (mx<da[i])mx=da[i];
}
for (lim=1;mx>1;mx=(__int64)sqrt((double)mx),lim++);
build(1,n,1);
scanf("%d",&o);
for (i=1;i<=o;i++)
{
int x,y,mark;
scanf("%d%d%d",&mark,&x,&y);
if (x>y)swap(x,y);
if (mark==0)
{
update(x,y,1,n,1);
}
else
{
printf("%I64d
",query(x,y,1,n,1));
}
}
printf("
");
}
return 0;
}
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
The 36th ACM/ICPC Asia Regional Shanghai Site —— Online Contest
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
9-1. 구조체와 클래스 비교, 구조체 개념(struct)구조체와 클래스는 프로그램 코드의 구성요소가 되는 범용 구조이다. 상수, 변수, 그리고 함수를 정의하는 것과 같은 구문을 사용해서 구조체와 클래스에 프로퍼티와 메서드를 기능적으로 추가할 수 있다. 스위프트에서 클래스...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.