# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1028448 |
2024-07-19T23:34:14 Z |
Dennis_Jason |
Addk (eJOI21_addk) |
C++14 |
|
2000 ms |
17312 KB |
#include <bitset>
#include <cmath>
#include <functional>
#include <algorithm>
#include <numeric>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <cstring>
#include <climits>
#define int long long
#define pb push_back
#define MOD 1000000007
#define NMAX 100005
#define nl '\n'
#define INF 1000000007
#define pii1 pair<int, pair<int,int>> (1,(1,2));
#define pii pair<int,int>
#define tpl tuple<int,int,int>
using namespace std;
ifstream fin("data.in");
ofstream fout("data.out");
class segtree{
private:
int n;
vector<vector<int>>tree;
public:
void init(int sz)
{
n=sz;
tree.resize(4*sz+1);
}
vector<int> calc(vector<int>a, vector<int>b)
{
for(auto x:b)
a.pb(x);
return a;
}
void build(int node,int st,int dr,vector<int>&v) {
if (st == dr) {
tree[node] = {v[st]};
return;
}
int mid = (st + dr) / 2;
build(2 * node, st, mid, v);
build(2 * node + 1, mid + 1, dr, v);
tree[node] = calc(tree[2 * node],tree[2 * node + 1]);
}
void update(int node,int st,int dr,int pos,int val)
{
if(st==dr)
{
tree[node]={val};
return;
}
int mid=(st+dr)/2;
if(pos<=mid)
update(2*node,st,mid,pos,val);
else
update(2*node+1,mid+1,dr,pos,val);
tree[node]=calc(tree[2*node],tree[2*node+1]);
}
vector<int> query(int node,int st,int dr,int L,int R)
{
if(R<st ||dr<L)
return {};
if(L<=st && dr<=R)
{
return tree[node];
}
int mid=(st+dr)/2;
vector<int> left=query(2*node,st,mid,L,R);
vector<int> right=query(2*node+1,mid+1,dr,L,R);
return calc(left,right);
}
void build(vector<int>&v)
{
build(1,1,n,v);
}
void update(int pos,int val)
{
update(1,1,n,pos,val);
}
vector<int> query(int L,int R)
{
return query(1,1,n,L,R);
}
};
/*
* 8 3
7 2 5 1 9 3 4 6
3
2 2 7 4
1 2 5 8
2 2 7 3
72519346
7251 9346
72 51 93 46
7 2 5 1 9 3 4 6
ind:
m=1 -> 7 2 5 1 9 3 4 6 -> 1 1 1 1 1 1 1 1
m=2 -> 7 2 2 5 5 1 1 9 9 3 3 4 4 6-> 1 2 2 2 2 2 2 1
m=3 -> 7 2 5 2 5 1 5 1 9 1 9 3 9 3 4 3 4 6 -> 1 2 3 3 3 3 2 1
/ m=4 -> 7 2 5 1 2 5 1 9 5 1 9 3 1 9 3 4 9 3 4 6-> 1 2 3 4 4 3 2 1
m=5 -> 7 2 5 1 9 2 5 1 9 3 5 1 9 3 4 1 9 3 4 6 -> 1 2 3 4 4 3 2 1
m=6 -> 7 2 5 1 9 3 4 6 2 5 1 9 3 4 6 5 1 9 3 4 6 -> 1 2 3 3 3 3 2 1
m=7 -> 7 2 5 1 9 3 4 2 5 1 9 3 4 6 ->1 2 2 2 2 2 2 1
m=8 7 2 5 1 9 3 4 6 -> 1 1 1 1 1 1 1 1
1 2 3 4 5 6 7 8 9 10 11 12
m=6 -> 1 2 3 4 5 6 2 3 4 5 6 7 3 4 5 6 7 8 4 5 6 7 8 9 5 6 7 8 9 10 6 7 8 9 10 11 7 8 9 10 11 12-> 1 2 3 4 5 6 6 5 4 3 2 1
lenght=m;
frq[ind][i]=min(i,m) ,ind<=length/2
frq[ind][i]frq[lenth-ind+1][i] ,ind>=length/2;
*/
segtree st;
signed main() {
int n,k;
cin>>n>>k;
vector<int>v(n+1);
st.init(n);
for(int i=1;i<=n;++i)
{
cin>>v[i];
}
st.build(v);
int q;
cin>>q;
while(q--)
{
int type;
cin>>type;
if(type==1)
{
int x;
for(int i=1;i<=k;++i)
{
cin>>x;
}
}
else
{
int l,r,m;
cin>>l>>r>>m;
vector<int>ans=st.query(l,r);
int res=0;
int aux=0;
int ind=0;
for(int i=0;i<m;++i)
{
aux+=ans[i];
}
res+=aux;
for(int i=m;i<ans.size();++i)
{
aux-=ans[ind];
aux+=ans[i];
ind++;
res+=aux;
}
cout<<res<<nl;
}
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:173:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
173 | for(int i=m;i<ans.size();++i)
| ~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
6 ms |
604 KB |
Output is correct |
3 |
Correct |
17 ms |
1140 KB |
Output is correct |
4 |
Correct |
33 ms |
1372 KB |
Output is correct |
5 |
Correct |
58 ms |
1768 KB |
Output is correct |
6 |
Correct |
113 ms |
2112 KB |
Output is correct |
7 |
Correct |
174 ms |
4776 KB |
Output is correct |
8 |
Correct |
232 ms |
2796 KB |
Output is correct |
9 |
Correct |
477 ms |
3816 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1652 ms |
7700 KB |
Output is correct |
2 |
Execution timed out |
2019 ms |
10512 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2062 ms |
17312 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |