Submission #1028448

#TimeUsernameProblemLanguageResultExecution timeMemory
1028448Dennis_JasonAddk (eJOI21_addk)C++14
36 / 100
2062 ms17312 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...