답안 #172708

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172708 2020-01-02T12:29:04 Z khohko Employment (JOI16_employment) C++17
100 / 100
204 ms 13888 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ARRS ((ll)(4e5+100))
#define fr first
#define sc second
#define pb push_back
#define MX ((ll)(1e9+100))
#define MAX ((ll)(1e18+100))


int n,q;
int a[ARRS];
int up[ARRS];
int type[ARRS];
pair<int, int> compress[ARRS];

int fw[2*ARRS];
int quer(int idx){
	int pas=0;
	for(;idx;idx-=idx&-idx)
		pas+=fw[idx];
	return pas;
}

void updt(int idx, int val){
	for(;idx<ARRS;idx+=idx&-idx)
		fw[idx]+=val;
}

void update_quer(int i, int k){
	if(i&&a[i-1]>a[i]){
		updt(a[i]+1, k);
		updt(a[i-1]+1, -k);
	}
}

int main(){
	scanf("%d %d", &n, &q);
	for(int i=0; i<n; i++){
		scanf("%d", &a[i]);
		compress[i]={a[i],i};
	}
	a[n]=0;
	compress[n]={a[n],n};
	n++;
	for(int i=n; i<n+q; i++){
		scanf("%d", &type[i]);
		if(type[i] == 1){//query
			scanf("%d", &a[i]);
		}
		else {//update
			scanf("%d %d", &up[i], &a[i]);
			up[i]--;
		}
		compress[i]={a[i],i};
	}
	sort(compress, compress+n+q);
	ll c=1;
	for(int i=0; i<n+q; i++){
		if(i&&compress[i].fr!=compress[i-1].fr)
			c++;
		a[compress[i].sc]=c;
	}
	for(int i=0; i<n; i++)
		update_quer(i, 1);
	for(int i=n; i<n+q; i++){
		if(type[i] == 1){
			printf("%d\n", quer(a[i]));
		}
		else {
			update_quer(up[i], -1);
			update_quer(up[i]+1, -1);
			a[up[i]]=a[i];
			update_quer(up[i], 1);
			update_quer(up[i]+1, 1);
		}
	}

}

Compilation message

employment.cpp: In function 'int main()':
employment.cpp:39:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &q);
  ~~~~~^~~~~~~~~~~~~~~~~
employment.cpp:41:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
employment.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &type[i]);
   ~~~~~^~~~~~~~~~~~~~~~
employment.cpp:50:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d", &a[i]);
    ~~~~~^~~~~~~~~~~~~
employment.cpp:53:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d", &up[i], &a[i]);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 372 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 4 ms 504 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 16 ms 1400 KB Output is correct
5 Correct 28 ms 2296 KB Output is correct
6 Correct 44 ms 3576 KB Output is correct
7 Correct 65 ms 4984 KB Output is correct
8 Correct 82 ms 6264 KB Output is correct
9 Correct 139 ms 10460 KB Output is correct
10 Correct 117 ms 8952 KB Output is correct
11 Correct 158 ms 11564 KB Output is correct
12 Correct 176 ms 12700 KB Output is correct
13 Correct 174 ms 12664 KB Output is correct
14 Correct 172 ms 12592 KB Output is correct
15 Correct 165 ms 12764 KB Output is correct
16 Correct 175 ms 12944 KB Output is correct
17 Correct 176 ms 12796 KB Output is correct
18 Correct 175 ms 13028 KB Output is correct
19 Correct 175 ms 12792 KB Output is correct
20 Correct 177 ms 12852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 3 ms 504 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 372 KB Output is correct
7 Correct 2 ms 504 KB Output is correct
8 Correct 3 ms 504 KB Output is correct
9 Correct 4 ms 504 KB Output is correct
10 Correct 5 ms 504 KB Output is correct
11 Correct 4 ms 632 KB Output is correct
12 Correct 5 ms 504 KB Output is correct
13 Correct 4 ms 504 KB Output is correct
14 Correct 4 ms 504 KB Output is correct
15 Correct 4 ms 504 KB Output is correct
16 Correct 4 ms 504 KB Output is correct
17 Correct 4 ms 504 KB Output is correct
18 Correct 4 ms 504 KB Output is correct
19 Correct 16 ms 1400 KB Output is correct
20 Correct 28 ms 2296 KB Output is correct
21 Correct 44 ms 3576 KB Output is correct
22 Correct 65 ms 4984 KB Output is correct
23 Correct 82 ms 6264 KB Output is correct
24 Correct 139 ms 10460 KB Output is correct
25 Correct 117 ms 8952 KB Output is correct
26 Correct 158 ms 11564 KB Output is correct
27 Correct 176 ms 12700 KB Output is correct
28 Correct 174 ms 12664 KB Output is correct
29 Correct 172 ms 12592 KB Output is correct
30 Correct 165 ms 12764 KB Output is correct
31 Correct 175 ms 12944 KB Output is correct
32 Correct 176 ms 12796 KB Output is correct
33 Correct 175 ms 13028 KB Output is correct
34 Correct 175 ms 12792 KB Output is correct
35 Correct 177 ms 12852 KB Output is correct
36 Correct 5 ms 504 KB Output is correct
37 Correct 1 ms 552 KB Output is correct
38 Correct 5 ms 632 KB Output is correct
39 Correct 17 ms 1400 KB Output is correct
40 Correct 29 ms 2296 KB Output is correct
41 Correct 48 ms 3548 KB Output is correct
42 Correct 67 ms 4984 KB Output is correct
43 Correct 89 ms 6412 KB Output is correct
44 Correct 163 ms 11280 KB Output is correct
45 Correct 131 ms 9316 KB Output is correct
46 Correct 148 ms 10368 KB Output is correct
47 Correct 197 ms 13276 KB Output is correct
48 Correct 200 ms 13624 KB Output is correct
49 Correct 195 ms 13556 KB Output is correct
50 Correct 194 ms 13304 KB Output is correct
51 Correct 204 ms 13708 KB Output is correct
52 Correct 201 ms 13672 KB Output is correct
53 Correct 203 ms 13580 KB Output is correct
54 Correct 199 ms 13888 KB Output is correct
55 Correct 196 ms 13688 KB Output is correct