답안 #871784

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
871784 2023-11-11T15:13:33 Z serifefedartar Bubble Sort 2 (JOI18_bubblesort2) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
#include "bubblesort2.h"
using namespace std;
 
#define fast ios::sync_with_stdio(0);cin.tie(0);
#define s second
#define f first
typedef long long ll;
const ll MOD = 1e9+9;
const ll LOGN = 20; 
const ll MAXN = 1e6 + 100;

vector<pair<int,int>> cc;
int index(pair<int,int> k) {
	return upper_bound(cc.begin(), cc.end(), k) - cc.begin();
}

int sg[4*MAXN], lazy[4*MAXN];
void push(int k, int a, int b) {
	if (lazy[k]) {
		sg[k] += lazy[k];
		if (a != b) {
			lazy[2*k] += lazy[k];
			lazy[2*k+1] += lazy[k];
		}
		return ;
	}
}

void update(int k, int a, int b, int q_l, int q_r, int val) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return ;
	if (q_l <= a && b <= q_r) {
		lazy[k] += val;
		push(k, a, b);
		return ;
	}
	update(2*k, a, (a+b)/2, q_l, q_r, val);
	update(2*k+1, (a+b)/2+1, b, q_l, q_r, val);
	sg[k] = max(sg[2*k], sg[2*k+1]);
}

int query(int k, int a, int b, int q_l, int q_r) {
	push(k, a, b);
	if (b < q_l || a > q_r)
		return 0;
	if (q_l <= a && b <= q_r)
		return sg[k];
	return max(query(2*k, a, (a+b)/2, q_l, q_r), query(2*k+1, (a+b)/2+1, b, q_l, q_r));
}

int N;
void add(pair<int,int> p) {
	int plc = index(p.f);
	update(1, 1, N, plc, plc, 1e7 + p.s);
	update(1, 1, N, plc + 1, N, -1); 
}

void omit(pair<int,int> p) {
	int plc = index(p.f);
	update(1, 1, N, plc, -1e7 - p.s);
	update(1, 1, N, plc + 1, N, 1);
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
	int n = A.size(), q = V.size();

	for (int i = 0; i < n; i++)
		cc.push_back({A[i], i}); 
	for (int i = 0; i < q; i++)
		cc.push_back({V[i], X[i]});

	N = cc.size();
	update(1, 1, N, -1e7);

	for (int i = 0; i < n; i++)
		add({A[i], i});

	vector<int> res;
	for (int i = 0; i < q; i++) {
		omit({A[X[i]], X[i]});
		add({V[i], X[i]});

		A[X[i]] = V[i];
		push(1, 1, N);
		res.push_back(sg[1]);
	}
	return res;
}

Compilation message

bubblesort2.cpp: In function 'void add(std::pair<int, int>)':
bubblesort2.cpp:55:21: error: no matching function for call to 'index(int&)'
   55 |  int plc = index(p.f);
      |                     ^
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from bubblesort2.cpp:1:
/usr/include/strings.h:55:1: note: candidate: 'char* index(char*, int)'
   55 | index (char *__s, int __c) __THROW
      | ^~~~~
/usr/include/strings.h:55:1: note:   candidate expects 2 arguments, 1 provided
/usr/include/strings.h:61:1: note: candidate: 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
/usr/include/strings.h:61:1: note:   candidate expects 2 arguments, 1 provided
bubblesort2.cpp:14:5: note: candidate: 'int index(std::pair<int, int>)'
   14 | int index(pair<int,int> k) {
      |     ^~~~~
bubblesort2.cpp:14:25: note:   no known conversion for argument 1 from 'int' to 'std::pair<int, int>'
   14 | int index(pair<int,int> k) {
      |           ~~~~~~~~~~~~~~^
bubblesort2.cpp: In function 'void omit(std::pair<int, int>)':
bubblesort2.cpp:61:21: error: no matching function for call to 'index(int&)'
   61 |  int plc = index(p.f);
      |                     ^
In file included from /usr/include/string.h:432,
                 from /usr/include/c++/10/cstring:42,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:48,
                 from bubblesort2.cpp:1:
/usr/include/strings.h:55:1: note: candidate: 'char* index(char*, int)'
   55 | index (char *__s, int __c) __THROW
      | ^~~~~
/usr/include/strings.h:55:1: note:   candidate expects 2 arguments, 1 provided
/usr/include/strings.h:61:1: note: candidate: 'const char* index(const char*, int)'
   61 | index (const char *__s, int __c) __THROW
      | ^~~~~
/usr/include/strings.h:61:1: note:   candidate expects 2 arguments, 1 provided
bubblesort2.cpp:14:5: note: candidate: 'int index(std::pair<int, int>)'
   14 | int index(pair<int,int> k) {
      |     ^~~~~
bubblesort2.cpp:14:25: note:   no known conversion for argument 1 from 'int' to 'std::pair<int, int>'
   14 | int index(pair<int,int> k) {
      |           ~~~~~~~~~~~~~~^
bubblesort2.cpp:62:33: error: too few arguments to function 'void update(int, int, int, int, int, int)'
   62 |  update(1, 1, N, plc, -1e7 - p.s);
      |                                 ^
bubblesort2.cpp:30:6: note: declared here
   30 | void update(int k, int a, int b, int q_l, int q_r, int val) {
      |      ^~~~~~
bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:75:22: error: too few arguments to function 'void update(int, int, int, int, int, int)'
   75 |  update(1, 1, N, -1e7);
      |                      ^
bubblesort2.cpp:30:6: note: declared here
   30 | void update(int k, int a, int b, int q_l, int q_r, int val) {
      |      ^~~~~~