Submission #335780

# Submission time Handle Problem Language Result Execution time Memory
335780 2020-12-14T02:29:36 Z Mo_TOI_I_am_Garbage Bubble Sort 2 (JOI18_bubblesort2) C++14
Compilation error
0 ms 0 KB
#include "bubblesort2.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
	int ans = 0;
	for(int i=1; i < A.size(); i ++)
		if(A[i] < A[i - 1]) ans ++;
	vector<int> res;
	for(int i=0; i < X.size(); i ++)
	{
		if(X[i] > 0 && A[X[i]] < A[X[i] - 1]) ans --;
		if(X[i] < A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans --;
		A[X[i]] = V[i];
		if(X[i] > 0 && A[X[i]] < A[X[i] - 1]) ans ++;
		if(X[i] < A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans ++;
		res.push_back(ans);
	}
	return res;
}


int readInt(){
	int i;
	if(scanf("%d",&i)!=1){
		fprintf(stderr,"Error while reading input\n");
		exit(1);
	}
	return i;
}

int main(){
	int N,Q;
	N=readInt();
	Q=readInt();
	
	std::vector<int> A(N);
	for(int i=0;i<N;i++)
		A[i]=readInt();
	
	std::vector<int> X(Q),V(Q);
	for(int j=0;j<Q;j++){
		X[j]=readInt();
		V[j]=readInt();
	}

	std::vector<int> res=countScans(A,X,V);
	

	for(int j=0;j<int(res.size());j++)
		printf("%d\n",res[j]);
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:7:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    7 |  for(int i=1; i < A.size(); i ++)
      |               ~~^~~~~~~~~~
bubblesort2.cpp:10:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   10 |  for(int i=0; i < X.size(); i ++)
      |               ~~^~~~~~~~~~
bubblesort2.cpp:13:11: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |   if(X[i] < A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans --;
bubblesort2.cpp:16:11: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |   if(X[i] < A.size() - 1 && A[X[i]] > A[X[i] + 1]) ans ++;
/tmp/ccqafyN7.o: In function `readInt()':
grader.cpp:(.text+0x0): multiple definition of `readInt()'
/tmp/ccKafY6X.o:bubblesort2.cpp:(.text+0x2b0): first defined here
/tmp/ccqafyN7.o: In function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'
/tmp/ccKafY6X.o:bubblesort2.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status