結果
| 問題 |
No.789 範囲の合計
|
| コンテスト | |
| ユーザー |
horiesiniti
|
| 提出日時 | 2018-03-20 18:21:04 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 236 ms / 1,000 ms |
| コード長 | 1,415 bytes |
| コンパイル時間 | 437 ms |
| コンパイル使用メモリ | 55,372 KB |
| 実行使用メモリ | 34,560 KB |
| 最終ジャッジ日時 | 2024-06-25 06:01:25 |
| 合計ジャッジ時間 | 3,232 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 |
コンパイルメッセージ
main.cpp: In function ‘E* f(int, int, int, int, E*)’:
main.cpp:30:1: warning: control reaches end of non-void function [-Wreturn-type]
30 | }
| ^
ソースコード
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
using namespace std;
struct E{
int n;
struct E *l;
struct E *r;
};
E* f(int x,int l,int r,int y,E *tree){
if((l<=x && x<=r)==false){
return tree;
}
if (tree == NULL) {
tree =(E*) malloc(sizeof(E));
tree->n = 0;
tree->l = NULL;
tree->r = NULL;
}
(tree->n)+=y;
if(l==r){
return tree;
}else if(l<=x && x<=r){
int m=(l+r)/2;
tree->l=f(x,l,m,y,tree->l);
tree->r=f(x,m+1,r,y,tree->r);
return tree;
}
}
long long int sum(int l,int r,int l2,int r2,E *tree){
if (tree == NULL){
return 0;
}else{
if(r<l2){
return 0;
}
if(r2<l){
return 0;
}
if (l2<=l&&r<=r2){
return tree->n;
}
int m=(l+r)/2;
long long int res=0;
res=sum(l,m,l2,r2,tree->l);
res+=sum(m+1,r,l2,r2,tree->r);
return res;
}
}
void delete_binary_tree(E *tree)
{
if( tree == NULL ){
return;
}
delete_binary_tree( tree->l );
delete_binary_tree( tree->r );
free( tree );
}
int main() {
// your code goes here
int x,n;
cin>>n;
long long int ans=0;
E *tree= (E*)malloc(sizeof(E));
tree->n = 0;
tree->l = NULL;
tree->r = NULL;
for(int i=0;i<n;i++){
cin>>x;
if(x==0){
int p1,y;
cin>>p1>>y;
f(p1,0,1073741823,y,tree);
}else{
int l,r;
cin>>l>>r;
ans+=sum(0,1073741823,l,r,tree);
}
}
cout<<ans<<"\n";
delete_binary_tree(tree);
return 0;
}
horiesiniti