49492023-04-07 19:05:13SleepyOverlordMI bróker (50 pont)cpp17Wrong answer 14/5041ms4752 KiB
#include <vector>
#include <string> 
#include <set> 
#include <map> 
#include <unordered_set>
#include <unordered_map>
#include <queue> 
#include <bitset> 
#include <stack>
#include <list>

#include <numeric> 
#include <algorithm> 
#include <random>
#include <chrono>

#include <cstdio>
#include <fstream>
#include <iostream> 
#include <sstream> 
#include <iomanip>
#include <climits>

#include <cctype>
#include <cmath> 
#include <ctime>
#include <cassert>

using namespace std;

#define ULL unsigned long long
#define LL long long
#define PII pair <int, int>
#define VB vector <bool>
#define VI vector <int>
#define VLL vector <LL>
#define VD vector <double>
#define VS vector <string>
#define VPII vector <pair <int, int> >
#define VVI vector < VI >
#define VVB vector < VB >
#define SI set < int >
#define USI unordered_set <int>
#define MII map <int, int>
#define UMII unordered_map <int, int>
#define MS multiset
#define US unordered_set
#define UM unordered_map
#define UMS unordered_multiset
#define UMM unordered_multimap

#define FORN(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for(int i = (a); i <= (b); ++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)

#define SZ size()
#define BG begin() 
#define EN end() 
#define CL clear()
#define X first
#define Y second
#define RS resize
#define PB push_back
#define MP make_pair
#define ALL(x) x.begin(), x.end()
#define INS insert
#define ER erase
#define CNT count

template <class T> ostream& operator <<(ostream & os, const vector<T> &vec)
{
	for (int i = 0; i < vec.size() - 1; ++i) os << vec[i] << ' ';
	return os << vec[vec.size() - 1];
}

template <class T1, class T2> ostream& operator <<(ostream & os, const pair<T1, T2> &p)
{
	return os << p.X << " " << p.Y;
}

template <typename T>
void pr(T var1)
{
	cout << var1 << '\n';
}
template <typename T, typename... Types>
void pr(T var1, Types... var2)
{
	cout << var1;
	pr(var2...);
}

int n, q, mn, mx;
VI a, prefMin;
VVI sol;

int main()
{
	#ifndef ONLINE_JUDGE
	freopen("a.in", "r", stdin);
	freopen("a.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

	cin >> n >> q;
	mn = 500, mx = 0;
	a.RS(n + 1);
	prefMin.RS(n + 1);
	prefMin[0] = 500;
	FOR(i, 1, n)
	{
		cin >> a[i];
		mn = min(mn, a[i]);
		mx = max(mx, a[i]);
		prefMin[i] = mn;
	}

	int profit = 0;
	bool has = false;
	FOR(k, 1, n)
		if (!has && a[k] <= mn) 
		{
			profit -= a[k];
			has = true;
		}
		else
			if (has && a[k] >= mx)
			{
				profit += a[k];
				has = false;
			}

	FOR(i, 1, q)
	{
		int x, y;
		cin >> x >> y;
		if (x < mn) cout << "0\n";
		else
			if (y > mx)
			{
				int l = 0, r = n;
				while (r - l > 1)
				{
					int m = (l + r) / 2;
					if (prefMin[m] > x) l = m;
					else r = m;
				}
				cout << -prefMin[r] << "\n";
			}
			else cout << profit << "\n";
	}

	return 0;
}
SubtaskSumTestVerdictTimeMemory
base14/50
1Wrong answer0/03ms1888 KiB
2Wrong answer0/025ms2352 KiB
3Accepted1/13ms2424 KiB
4Accepted1/13ms2380 KiB
5Wrong answer0/23ms2520 KiB
6Wrong answer0/23ms2932 KiB
7Wrong answer0/24ms3140 KiB
8Accepted1/139ms3220 KiB
9Accepted1/139ms3212 KiB
10Accepted2/241ms3220 KiB
11Accepted2/241ms3504 KiB
12Accepted2/241ms3716 KiB
13Accepted2/241ms3772 KiB
14Accepted2/241ms4144 KiB
15Wrong answer0/339ms3920 KiB
16Wrong answer0/339ms4132 KiB
17Wrong answer0/339ms4196 KiB
18Wrong answer0/339ms4320 KiB
19Wrong answer0/339ms4524 KiB
20Wrong answer0/339ms4524 KiB
21Wrong answer0/339ms4532 KiB
22Wrong answer0/339ms4748 KiB
23Wrong answer0/339ms4736 KiB
24Wrong answer0/339ms4752 KiB