結果
問題 | No.789 範囲の合計 |
ユーザー | 👑 horiesiniti |
提出日時 | 2018-03-20 18:21:04 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 240 ms / 1,000 ms |
コード長 | 1,415 bytes |
コンパイル時間 | 607 ms |
コンパイル使用メモリ | 51,596 KB |
実行使用メモリ | 34,624 KB |
最終ジャッジ日時 | 2023-09-07 11:53:19 |
合計ジャッジ時間 | 3,715 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 222 ms
28,540 KB |
testcase_03 | AC | 77 ms
4,380 KB |
testcase_04 | AC | 240 ms
31,704 KB |
testcase_05 | AC | 196 ms
27,536 KB |
testcase_06 | AC | 200 ms
28,592 KB |
testcase_07 | AC | 73 ms
4,376 KB |
testcase_08 | AC | 215 ms
34,624 KB |
testcase_09 | AC | 200 ms
31,844 KB |
testcase_10 | AC | 187 ms
20,012 KB |
testcase_11 | AC | 157 ms
28,116 KB |
testcase_12 | AC | 164 ms
28,096 KB |
testcase_13 | AC | 2 ms
4,380 KB |
testcase_14 | AC | 1 ms
4,376 KB |
コンパイルメッセージ
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] } ^
ソースコード
#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; }