Submission #1338141

#TimeUsernameProblemLanguageResultExecution timeMemory
1338141salmonBubble Sort Machine (JOI25_bubble)C++20
5 / 100
2094 ms13864 KiB
#include <bits/stdc++.h>
using namespace std;

int N;
int lst[500100];
int Q;
long long int pre[500100];

int main(){
	
	scanf(" %d",&N);
	
	for(int i = 1; i <= N; i++){
		scanf(" %d",&lst[i]);
	}
	
	scanf(" %d",&Q);
	
	pre[0] = 0;
			for(int i = 1; i <= N; i++) pre[i] = pre[i - 1] + lst[i];
	
	for(int i = 0; i < Q; i++){
		int T;
		
		scanf(" %d",&T);
		
		if(T == 1){
			for(int i = 1; i <= N - 1; i++){
				if(lst[i] > lst[i + 1]) swap(lst[i],lst[i + 1]);
			}
			pre[0] = 0;
			
			for(int i = 1; i <= N; i++) pre[i] = pre[i - 1] + lst[i];
		}
		else{
			int l,r;
			
			scanf(" %d",&l);
			scanf(" %d",&r);
			
			printf("%lld\n",pre[r] - pre[l - 1]);
		}
	}
	
}

Compilation message (stderr)

bubble.cpp: In function 'int main()':
bubble.cpp:11:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |         scanf(" %d",&N);
      |         ~~~~~^~~~~~~~~~
bubble.cpp:14:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |                 scanf(" %d",&lst[i]);
      |                 ~~~~~^~~~~~~~~~~~~~~
bubble.cpp:17:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         scanf(" %d",&Q);
      |         ~~~~~^~~~~~~~~~
bubble.cpp:25:22: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |                 scanf(" %d",&T);
      |                 ~~~~~^~~~~~~~~~
bubble.cpp:38:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |                         scanf(" %d",&l);
      |                         ~~~~~^~~~~~~~~~
bubble.cpp:39:30: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |                         scanf(" %d",&r);
      |                         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...