# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
997437 |
2024-06-12T10:23:56 Z |
cpdreamer |
Addk (eJOI21_addk) |
C++17 |
|
33 ms |
2904 KB |
#include <bits/stdc++.h>
#include <climits>
#include <ext/pb_ds/assoc_container.hpp>
#include <utility>
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,
tree_order_statistics_node_update> indexed_set;
const int max_n=INT_MAX;
typedef long long ll;
#define LLM LONG_LONG_MAX
#define pb push_back
#define F first
#define P pair
#define L length()
#define all(v) v.begin(),v.end()
#define V vector
#define S second
const long long MOD = 99824433; // 1e9 + 7
void file(){
freopen("input.txt.txt","r",stdin);
freopen("output.txt.txt","w",stdout);
}
void setio(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
struct segtree{
private:
struct node{
ll sum;
};
static node single(int v){
return {v};
}
node neutral={0LL};
static node merge(node a ,node b){
return{a.sum+b.sum};
}
public:
int size;
V<node>query;
void init(int n){
size=1;
while(size<n)size*=2;
query.assign(2*size,neutral);
}
void build(V<ll>&a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<a.size())
query[x]=single(a[lx]);
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
query[x]=merge(query[2*x+1],query[2*x+2]);
}
void build(V<ll>&a){
build(a,0,0,size);
}
node calc(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l)
return neutral;
if(l<=lx && rx<=r)
return query[x];
int m=(lx+rx)/2;
node a=calc(l,r,2*x+1,lx,m);
node b=calc(l,r,2*x+2,m,rx);
return merge(a,b);
}
long long calc(int l,int r){
return calc(l,r,0,0,size).sum;
}
};
void solve(){
int n;
cin>>n;
int k;
cin>>k;
V<ll>a(n+1);
a[0]=0;
for(int i=1;i<=n;i++){
cin>>a[i];
a[i]+=a[i-1];
}
segtree tree;
tree.init(n+1);
tree.build(a);
int q;
cin>>q;
while(q--){
int type;
cin>>type;
if(type==2){
int m,l,r;
cin>>l>>r>>m;
ll x=tree.calc(l+m-1,r+1)-tree.calc(l,r-m+1);
int left=r-m+1-l;
int right=r+1-l-m+1;
x+=(left-right)*a[l-1];
cout<<x<<endl;
}
else{
int b;cin>>b;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
//file();
solve();
return 0;
}
Compilation message
Main.cpp: In member function 'void segtree::build(std::vector<long long int>&, int, int, int)':
Main.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | if(lx<a.size())
| ~~^~~~~~~~~
Main.cpp: In function 'void file()':
Main.cpp:23:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen("input.txt.txt","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | freopen("output.txt.txt","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp: In function 'void setio(std::string)':
Main.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:28:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
464 KB |
Output is correct |
4 |
Correct |
5 ms |
604 KB |
Output is correct |
5 |
Correct |
6 ms |
660 KB |
Output is correct |
6 |
Incorrect |
8 ms |
788 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
33 ms |
1724 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
18 ms |
2904 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |