Submission #1030907

# Submission time Handle Problem Language Result Execution time Memory
1030907 2024-07-22T11:46:58 Z vahagng Addk (eJOI21_addk) C++17
92 / 100
41 ms 8020 KB
//----------vahagng----------//
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
using namespace std;
// using namespace __gnu_pbds;

// template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#ifndef ONLINE_JUDGE
#define dbg(x) cerr << #x <<" "; print(x); cerr << endl;
#else
#define dbg(x)
#endif

void print(long long t) {cerr << t;}
void print(int t) {cerr << t;}
void print(string t) {cerr << t;}
void print(char t) {cerr << t;}
void print(double t) {cerr << t;}
void print(long double t) {cerr << t;}
void print(unsigned long long t) {cerr << t;}

template <class T, class V> void print(pair <T, V> p);
template <class T> void print(vector <T> v);
template <class T> void print(set <T> v);
template <class T, class V> void print(map <T, V> v);
template <class T> void print(multiset <T> v);
template <class T, class V> void print(T v[],V n) {cerr << "["; for(int i = 0; i < n; i++) {cerr << v[i] << " ";} cerr << "]";}
template <class T, class V> void print(pair <T, V> p) {cerr << "{"; print(p.first); cerr << ","; print(p.second); cerr << "}";}
template <class T> void print(vector <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(set <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T> void print(multiset <T> v) {cerr << "[ "; for (T i : v) {print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void print(map <T, V> v) {cerr << "[ "; for (auto i : v) {print(i); cerr << " ";} cerr << "]";}
 

// Defines

#define ll long long
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pii pair<int, int>
#define ppb pop_back
#define pb push_back
#define mii map<int, int>
#define mll map<long long, long long>
#define no_ans cout << -1 << '\n';
#define YES cout << "YES\n";
#define NO cout << "NO\n";
#define ok cout << "OK\n";
#define ld long double
#define sz(v) v.size()
#define endl '\n'
// Constants 

const int N = 10000000, M = 3e5+10;
const ll inf = 1e18, mod = 1e9+7, mod1 = 998244353;

// Functions

void SetIO(string str = "") {
    if (str != "") {
        freopen((str + ".in").c_str(), "r", stdin);
        freopen((str + ".out").c_str(), "w", stdout);
    } else {
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    }
}
 
void FastIO() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

ll add(ll a, ll b)
{
    return (a + b)%mod;
}

ll mult(ll a, ll b)
{
    return (a%mod * b%mod)%mod;
}

ll sub(ll a, ll b)
{
    return (a - b + 2*mod)%mod;
}

long long binpower(long long a, long long n) {
	if(n == 0) {
		return 1;
	}
 
	if(n == 1) {
		return a;
	}
 
	if(n % 2 == 1) {
		long long curr = binpower(a, n / 2);
		curr = mult(curr, curr);
		curr = mult(a, curr);
		return curr;
	} else {
		long long curr = binpower(a, n / 2);
		return mult(curr, curr);
	}
}


//Solution

ll n, q, a[N], k, p[N], P1[N], P2[N];

/*
8 1
7 2 5 1 9 3 4 6
1
2 2 7 4
*/

//l-1 ic r - k - 1 hanum = x
// r - k + 1 ic r gumarum = y
// patasxan x + y

void solve(int tc)
{
    cin >> n >> k;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
        p[i] = p[i-1] + a[i];
    }
    for(int i = 1; i <= n; i++)
    {
        P1[i] = P1[i-1] + p[i];
        // P2[i] = P2[i-1] - p[i];
    }
    cin >> q;
    while(q--)
    {
        int type;
        cin >> type;
        if(type == 1)
        {
            int x;
            cin >> x;
        }else{
            int l, r, m;
            cin >> l >> r >> m;
            cout << (P1[r] - P1[r - m]) - (P1[l + m - 2] - P1[max(l - 2, 0)]) << endl;
        }
    }
}

void precalc()
{

}

int main() {
    // SetIO("");
    FastIO();
    int test_case = 1;
    // cin >> test_case;
    precalc();
    int cnt = 1;
    while (test_case--)
    {
      solve(cnt++);
    }
    return 0;
}

Compilation message

Main.cpp: In function 'void SetIO(std::string)':
Main.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen((str + ".in").c_str(), "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:64:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |         freopen((str + ".out").c_str(), "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2604 KB Output is correct
5 Correct 3 ms 2652 KB Output is correct
6 Correct 2 ms 2652 KB Output is correct
7 Correct 2 ms 2652 KB Output is correct
8 Correct 2 ms 2652 KB Output is correct
9 Correct 4 ms 2904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 3416 KB Output is correct
2 Correct 10 ms 3932 KB Output is correct
3 Correct 13 ms 4700 KB Output is correct
4 Correct 22 ms 6316 KB Output is correct
5 Correct 34 ms 8020 KB Output is correct
6 Correct 32 ms 7764 KB Output is correct
7 Correct 41 ms 7760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 18 ms 5468 KB Output isn't correct
2 Halted 0 ms 0 KB -