Submission #863895

# Submission time Handle Problem Language Result Execution time Memory
863895 2023-10-21T10:56:06 Z FIFI_cpp Addk (eJOI21_addk) C++17
36 / 100
2000 ms 6152 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <stdio.h>
#include <math.h>
#include <queue>
#include <stack>
#include <deque>
#include <fstream>
#include <iterator>
#include <set>
#include <map>
#include <iomanip>
#define ll long long
using namespace std;
map<int,ll> nums;
ll prefix[100001];
void sw (int k1,int k2)
{
    ll inter = nums[k2];
    nums[k2] = nums[k1];
    nums[k1] = inter;
    
}
void init_pref()
{
    ll curr = 0;
    for (auto it:nums)
    {
        curr+=it.second;
        prefix[it.first + 1] = curr;
    }
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;
    cin >> n >> k;
    ll curr = 0;
    for (int i = 0;i < n;i++)
    {
        ll inter = 0;
        cin >> inter;
        nums[i] = inter;
    }
    init_pref();
    int q;
    cin >> q;
    while (q--)
    {
        int type;
        cin >> type;
        if (type == 1)
        {
            vector<int> pos(k,0);
            for (int i = 0;i < k;i++)
            {
                cin >> pos[i];
            }
            sw(pos[0] - 1,pos[k - 1] - 1);
            for (int i = 0;i < k - 2;i++)
            {
                sw(pos[i] - 1,pos[i + 1] - 1);
            }
            init_pref();
        }
        else
        {
            int begin,end,size;
            cin >> begin >> end >> size;
            int c_begin = begin;
            int c_end = begin + size - 1;
            ll curr_sum = 0;
            while (c_end <= end)
            {
                curr_sum += prefix[c_end] - prefix[c_begin - 1];
                c_end++;
                c_begin++;
            }
            cout << curr_sum << '\n';
        }
    }
    return 0;
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:42:8: warning: unused variable 'curr' [-Wunused-variable]
   42 |     ll curr = 0;
      |        ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 5 ms 604 KB Output is correct
5 Correct 9 ms 604 KB Output is correct
6 Correct 13 ms 872 KB Output is correct
7 Correct 18 ms 856 KB Output is correct
8 Correct 25 ms 988 KB Output is correct
9 Correct 52 ms 1244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 189 ms 2128 KB Output is correct
2 Correct 428 ms 3052 KB Output is correct
3 Correct 748 ms 3924 KB Output is correct
4 Execution timed out 2049 ms 6152 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2051 ms 4276 KB Time limit exceeded
2 Halted 0 ms 0 KB -