Submission #144370

# Submission time Handle Problem Language Result Execution time Memory
144370 2019-08-16T18:18:44 Z arayi Tenis (COI19_tenis) C++17
100 / 100
248 ms 8048 KB
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <math.h>
#include <vector>
#include <cstring>
#include <ctime>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#define fr first
#define sc second
#define MP make_pair
#define PB push_back
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define lli long long int
#define y1 arayikhalatyan
using namespace std;

lli gcd(lli a, lli b) {
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
lli cg(lli n) {
	return n ^ (n >> 1);
}
lli SUM(lli a)
{
	return (a * (a + 1) / 2);
}
bool CAN(int x, int y, int n, int m)
{
	if (x >= 0 && y >= 0 && x < n && y < m)
	{
		return true;
	}
	return false;
}
double her(double x1, double y1, double x2, double y2)
{
	return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
string strsum(string a, string b)
{
	int p = 0;
	string c;
	reverse(a.begin(), a.end());
	reverse(b.begin(), b.end());
	if (b.length() < a.length())
	{
		for (int i = b.length(); i < a.length(); i++)
		{
			b += "0";
		}
	}
	else
	{
		for (int i = a.length(); i < b.length(); i++)
		{
			a += "0";
		}
	}

	a += "0", b += "0";
	for (int i = 0; i < a.length(); i++)
	{
		c += (a[i] - '0' + b[i] - '0' + p) % 10 + '0';
		p = (a[i] + b[i] - '0' - '0' + p) / 10;
	}
	if (c[c.length() - 1] == '0') c.erase(c.length() - 1, 1);
	reverse(c.begin(), c.end());
	return c;
}
string strmin(string a, string b)
{
	if (a.length() > b.length()) return b;
	if (b.length() > a.length()) return a;
	for (int i = 0; i < a.length(); i++)
	{
		if (a[i] > b[i]) return b;
		if (b[i] > a[i]) return a;
	}
	return a;
}

char vow[] = { 'a', 'e', 'i', 'o', 'u' };
int dx[] = { 1, -1, 0, 0 };
int dy[] = { 0, 0, 1, -1 };



const int N = 2e5 + 30;
const lli mod = 998244353;

pair <int, int> t[4 * N];
int flag[4 * N];
int n, q, sm;
int a[3][N], m[N], c[N], b[3][N];
void push(int nd)
{
	t[nd].fr += flag[nd];
	flag[2 * nd] += flag[nd];
	flag[2 * nd + 1] += flag[nd];
	flag[nd] = 0;
}
void build(int nl = 1, int nr = n, int nd = 1)
{
	if (nl == nr)
	{
		t[nd] = MP(c[nl], nl);
		return;
	}
	int mid = (nl + nr) / 2;
	build(nl, mid, 2 * nd);
	build(mid + 1, nr, 2 * nd + 1);
	t[nd] = min(t[2 * nd], t[2 * nd + 1]);
}
void update(int val, int ql, int qr = n, int nl = 1, int nr = n, int nd = 1)
{
	if (ql > qr || ql > nr || nl > qr) return;
	
	if (ql == nl && qr == nr)
	{
		//cout << t[nd].fr << " " << t[nd].sc << " " << flag[nd] << endl;
		flag[nd] += val;
		if (nl != nr)
		{
			push(nd);
			push(2 * nd);
			push(2 * nd + 1);
			t[nd] = min(t[2 * nd], t[2 * nd + 1]);
		}
		//cout << ql << " " << qr << " " << nl << " " << nr << " " << nd << "  ";
		//cout << t[nd].fr << " " << t[nd].sc << endl;
		return;
	}
	push(nd);
	int mid = (nl + nr) / 2;
	update(val, ql, min(mid, qr), nl, mid, 2 * nd);
	update(val, max(mid + 1, ql), qr, mid + 1, nr, 2 * nd + 1);
	push(2 * nd);
	push(2 * nd + 1);
	t[nd] = min(t[2 * nd], t[2 * nd + 1]);
	//cout << ql << " " << qr << " " << nl << " " << nr << " " << nd << "  ";
	//cout << t[nd].fr << " " << t[nd].sc << endl;
}
void tp()
{
	for (int i = 1; i <= n; i++)
	{
		cout << c[i] << " ";
	}
	cout << endl;
}
int main()
{
	fastio;
	//freopen("c.in", "r", stdin);
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[0][i];
		m[a[0][i]] = i;
		b[0][a[0][i]] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> a[1][i];
		m[a[1][i]] = max(m[a[1][i]], i);
		b[1][a[1][i]] = i;
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> a[2][i];
		m[a[2][i]] = max(m[a[2][i]], i);
		b[2][a[2][i]] = i;
	}
	for (int i = 1; i <= n; i++) c[m[i]]++;
	//cout << endl;
	for (int i = 1; i <= n; i++) c[i] += c[i - 1];
	for (int i = 1; i <= n; i++) c[i] = i - c[i];
	for (int i = 1; i <= n; i++)
	{
		if (c[i] == 0)
		{
			sm = i;
			break;
		}
	}
	build();
	//cout << c[2] << endl;
	//cout << t[1].sc << endl << endl;
	//tp();
	//cout << sm << endl;
	for (int i = 0; i < q; i++)
	{
		int A;
		cin >> A;
		if (A == 1)
		{
			int x;
			cin >> x;
			if (m[x] <= sm)	cout << "DA\n";
			else cout << "NE\n";
		}
		else
		{
			int p, i1, i2;
			cin >> p >> i1 >> i2;
			p--;
			swap(a[p][b[p][i1]], a[p][b[p][i2]]);
			swap(b[p][i1], b[p][i2]);
			update(1, m[i1]);
			m[i1] = max(b[0][i1], max(b[1][i1], b[2][i1]));
			update(-1, m[i1]);
			update(1, m[i2]);
			m[i2] = max(b[0][i2], max(b[1][i2], b[2][i2]));
			update(-1, m[i2]);
			sm = t[1].sc;
			//cout << t[1].sc << endl;
			//tp();
		}
	}
	return 0;
}

Compilation message

tenis.cpp: In function 'std::__cxx11::string strsum(std::__cxx11::string, std::__cxx11::string)':
tenis.cpp:57:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = b.length(); i < a.length(); i++)
                            ~~^~~~~~~~~~~~
tenis.cpp:64:30: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for (int i = a.length(); i < b.length(); i++)
                            ~~^~~~~~~~~~~~
tenis.cpp:71:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
tenis.cpp: In function 'std::__cxx11::string strmin(std::__cxx11::string, std::__cxx11::string)':
tenis.cpp:84:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < a.length(); i++)
                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 436 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 436 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 49 ms 5752 KB Output is correct
14 Correct 46 ms 5676 KB Output is correct
15 Correct 46 ms 5624 KB Output is correct
16 Correct 47 ms 5760 KB Output is correct
17 Correct 45 ms 5624 KB Output is correct
18 Correct 45 ms 5624 KB Output is correct
19 Correct 47 ms 5496 KB Output is correct
20 Correct 51 ms 5596 KB Output is correct
21 Correct 45 ms 5600 KB Output is correct
22 Correct 91 ms 5624 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 5880 KB Output is correct
2 Correct 69 ms 6008 KB Output is correct
3 Correct 66 ms 5880 KB Output is correct
4 Correct 67 ms 5880 KB Output is correct
5 Correct 68 ms 5896 KB Output is correct
6 Correct 70 ms 5880 KB Output is correct
7 Correct 65 ms 6008 KB Output is correct
8 Correct 66 ms 6008 KB Output is correct
9 Correct 66 ms 5880 KB Output is correct
10 Correct 65 ms 5880 KB Output is correct
11 Correct 67 ms 5820 KB Output is correct
12 Correct 65 ms 5880 KB Output is correct
13 Correct 68 ms 5916 KB Output is correct
14 Correct 67 ms 5880 KB Output is correct
15 Correct 68 ms 5988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 380 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 2 ms 436 KB Output is correct
9 Correct 2 ms 504 KB Output is correct
10 Correct 2 ms 504 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 49 ms 5752 KB Output is correct
14 Correct 46 ms 5676 KB Output is correct
15 Correct 46 ms 5624 KB Output is correct
16 Correct 47 ms 5760 KB Output is correct
17 Correct 45 ms 5624 KB Output is correct
18 Correct 45 ms 5624 KB Output is correct
19 Correct 47 ms 5496 KB Output is correct
20 Correct 51 ms 5596 KB Output is correct
21 Correct 45 ms 5600 KB Output is correct
22 Correct 91 ms 5624 KB Output is correct
23 Correct 67 ms 5880 KB Output is correct
24 Correct 69 ms 6008 KB Output is correct
25 Correct 66 ms 5880 KB Output is correct
26 Correct 67 ms 5880 KB Output is correct
27 Correct 68 ms 5896 KB Output is correct
28 Correct 70 ms 5880 KB Output is correct
29 Correct 65 ms 6008 KB Output is correct
30 Correct 66 ms 6008 KB Output is correct
31 Correct 66 ms 5880 KB Output is correct
32 Correct 65 ms 5880 KB Output is correct
33 Correct 67 ms 5820 KB Output is correct
34 Correct 65 ms 5880 KB Output is correct
35 Correct 68 ms 5916 KB Output is correct
36 Correct 67 ms 5880 KB Output is correct
37 Correct 68 ms 5988 KB Output is correct
38 Correct 248 ms 7772 KB Output is correct
39 Correct 108 ms 5880 KB Output is correct
40 Correct 248 ms 7924 KB Output is correct
41 Correct 138 ms 5808 KB Output is correct
42 Correct 140 ms 5752 KB Output is correct
43 Correct 243 ms 7740 KB Output is correct
44 Correct 111 ms 5980 KB Output is correct
45 Correct 143 ms 5796 KB Output is correct
46 Correct 107 ms 5752 KB Output is correct
47 Correct 135 ms 5880 KB Output is correct
48 Correct 108 ms 5880 KB Output is correct
49 Correct 142 ms 7420 KB Output is correct
50 Correct 105 ms 6008 KB Output is correct
51 Correct 139 ms 5880 KB Output is correct
52 Correct 239 ms 6712 KB Output is correct
53 Correct 116 ms 5860 KB Output is correct
54 Correct 126 ms 5724 KB Output is correct
55 Correct 145 ms 5756 KB Output is correct
56 Correct 132 ms 5880 KB Output is correct
57 Correct 108 ms 5880 KB Output is correct
58 Correct 168 ms 8048 KB Output is correct