답안 #902697

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
902697 2024-01-11T00:30:05 Z KN200711 Fancy Fence (CEOI20_fancyfence) C++14
컴파일 오류
0 ms 0 KB
# include <bits/stdc++.h># define ll long long# define ld long double# define fi first# define se second# define pll pair<ll, ll># define pdd pair<ld, ld># define pii pair<int, int>using namespace std; const ll MOD = 1e9 + 7; int par[100001];ll sz[100001], ans[100001]; ll C2(int a) {	ll v = a * (a + 1ll) / 2ll;	v %= MOD;	return v;} int find(int a) {	if(a == par[a]) return a;	par[a] = find(par[a]);	return par[a];} void merge(int a, int b, ll c) {	a = find(a);	b = find(b);	if(a == b) return;	ans[a] += ans[b];	ans[a] %= MOD;		ll G = C2(c) * (C2(sz[a]) + C2(sz[b]));	G %= MOD;	
	par[b] = a;
	sz[a] += sz[b];
	sz[a] %= MOD;
	ans[a] -= G;
	ans[a] %= MOD;
	
	G = C2(c) * (C2(sz[a]));
	G %= MOD;
	
	ans[a] += G;
	ans[a] %= MOD;
}
 
bool vis[100001];
 
int main() {
	int N;
	scanf("%d", &N);
	vector<pair<pii, int> > arr(N);
	for(int i=0;i<N;i++) {
		par[i] = i;
		scanf("%d", &arr[i].fi.fi);
	}
	for(int i=0;i<N;i++) {
		scanf("%d", &arr[i].fi.se);
		ans[i] = C2(arr[i].fi.fi) * C2(arr[i].fi.se);
		sz[i] = arr[i].fi.se;
		ans[i] %= MOD;
		arr[i].se = i;
	}
	sort(arr.begin(), arr.end());
	for(int i=N-1;i>=0;i--) {
		int idx = arr[i].se;
		vis[idx] = 1;
		if(idx > 0 && vis[idx - 1]) merge(idx - 1, idx, arr[i].fi.fi);
		if(idx + 1 < N && vis[idx + 1]) merge(idx + 1, idx, arr[i].fi.fi);
	}
	if(ans[find(0)] < 0) ans[find(0)] += MOD;
	printf("%lld\n", ans[find(0)]);
}

Compilation message

fancyfence.cpp:1:26: warning: extra tokens at end of #include directive
    1 | # include <bits/stdc++.h># define ll long long# define ld long double# define fi first# define se second# define pll pair<ll, ll># define pdd pair<ld, ld># define pii pair<int, int>using namespace std; const ll MOD = 1e9 + 7; int par[100001];ll sz[100001], ans[100001]; ll C2(int a) { ll v = a * (a + 1ll) / 2ll; v %= MOD; return v;} int find(int a) { if(a == par[a]) return a; par[a] = find(par[a]); return par[a];} void merge(int a, int b, ll c) { a = find(a); b = find(b); if(a == b) return; ans[a] += ans[b]; ans[a] %= MOD;  ll G = C2(c) * (C2(sz[a]) + C2(sz[b])); G %= MOD;
      |                          ^
fancyfence.cpp:1:2: error: 'par' does not name a type
    1 | # include <bits/stdc++.h># define ll long long# define ld long double# define fi first# define se second# define pll pair<ll, ll># define pdd pair<ld, ld># define pii pair<int, int>using namespace std; const ll MOD = 1e9 + 7; int par[100001];ll sz[100001], ans[100001]; ll C2(int a) { ll v = a * (a + 1ll) / 2ll; v %= MOD; return v;} int find(int a) { if(a == par[a]) return a; par[a] = find(par[a]); return par[a];} void merge(int a, int b, ll c) { a = find(a); b = find(b); if(a == b) return; ans[a] += ans[b]; ans[a] %= MOD;  ll G = C2(c) * (C2(sz[a]) + C2(sz[b])); G %= MOD;
      |  ^~~
fancyfence.cpp:2:2: error: 'sz' does not name a type
    2 |  par[b] = a;
      |  ^~
fancyfence.cpp:3:2: error: 'sz' does not name a type
    3 |  sz[a] += sz[b];
      |  ^~
fancyfence.cpp:4:2: error: 'ans' does not name a type; did you mean 'abs'?
    4 |  sz[a] %= MOD;
      |  ^~~
      |  abs
fancyfence.cpp:5:2: error: 'ans' does not name a type; did you mean 'abs'?
    5 |  ans[a] -= G;
      |  ^~~
      |  abs
fancyfence.cpp:7:2: error: 'G' does not name a type
    7 | 
      |  ^
fancyfence.cpp:8:2: error: 'G' does not name a type
    8 |  G = C2(c) * (C2(sz[a]));
      |  ^
fancyfence.cpp:10:2: error: 'ans' does not name a type; did you mean 'abs'?
   10 | 
      |  ^  
      |  abs
fancyfence.cpp:11:2: error: 'ans' does not name a type; did you mean 'abs'?
   11 |  ans[a] += G;
      |  ^~~
      |  abs
fancyfence.cpp:12:1: error: expected declaration before '}' token
   12 |  ans[a] %= MOD;
      | ^
fancyfence.cpp: In function 'int main()':
fancyfence.cpp:19:2: error: 'vector' was not declared in this scope; did you mean 'std::vector'?
   19 |  scanf("%d", &N);
      |  ^~~~~~
      |  std::vector
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/queue:61,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:389:11: note: 'std::vector' declared here
  389 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
fancyfence.cpp:19:9: error: 'pair' was not declared in this scope; did you mean 'std::pair'?
   19 |  scanf("%d", &N);
      |         ^~~~
      |         std::pair
In file included from /usr/include/c++/10/bits/stl_algobase.h:64,
                 from /usr/include/c++/10/bits/char_traits.h:39,
                 from /usr/include/c++/10/ios:40,
                 from /usr/include/c++/10/istream:38,
                 from /usr/include/c++/10/sstream:38,
                 from /usr/include/c++/10/complex:45,
                 from /usr/include/c++/10/ccomplex:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:54,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_pair.h:211:12: note: 'std::pair' declared here
  211 |     struct pair
      |            ^~~~
fancyfence.cpp:19:14: error: 'pii' was not declared in this scope
   19 |  scanf("%d", &N);
      |              ^~~
fancyfence.cpp:19:19: error: expected primary-expression before 'int'
   19 |  scanf("%d", &N);
      |                   ^  
fancyfence.cpp:21:3: error: 'par' was not declared in this scope
   21 |  for(int i=0;i<N;i++) {
      |   ^~~
fancyfence.cpp:22:16: error: 'arr' was not declared in this scope
   22 |   par[i] = i;
      |                ^  
fancyfence.cpp:25:16: error: 'arr' was not declared in this scope
   25 |  for(int i=0;i<N;i++) {
      |                ^~~
fancyfence.cpp:26:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
   26 |   scanf("%d", &arr[i].fi.se);
      |   ^~~
      |   abs
fancyfence.cpp:26:12: error: 'C2' was not declared in this scope
   26 |   scanf("%d", &arr[i].fi.se);
      |            ^~
fancyfence.cpp:27:3: error: 'sz' was not declared in this scope
   27 |   ans[i] = C2(arr[i].fi.fi) * C2(arr[i].fi.se);
      |   ^~
fancyfence.cpp:28:13: error: 'MOD' was not declared in this scope
   28 |   sz[i] = arr[i].fi.se;
      |             ^~~
fancyfence.cpp:31:7: error: 'arr' was not declared in this scope
   31 |  }
      |       ^  
fancyfence.cpp:31:2: error: 'sort' was not declared in this scope; did you mean 'std::sort'?
   31 |  }
      |  ^   
      |  std::sort
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4880:5: note: 'std::sort' declared here
 4880 |     sort(_RandomAccessIterator __first, _RandomAccessIterator __last,
      |     ^~~~
fancyfence.cpp:35:31: error: 'merge' was not declared in this scope; did you mean 'std::merge'?
   35 |   vis[idx] = 1;
      |                               ^    
      |                               std::merge
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4995:5: note: 'std::merge' declared here
 4995 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
fancyfence.cpp:36:35: error: 'merge' was not declared in this scope; did you mean 'std::merge'?
   36 |   if(idx > 0 && vis[idx - 1]) merge(idx - 1, idx, arr[i].fi.fi);
      |                                   ^~~~~
      |                                   std::merge
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4995:5: note: 'std::merge' declared here
 4995 |     merge(_InputIterator1 __first1, _InputIterator1 __last1,
      |     ^~~~~
fancyfence.cpp:38:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   38 |  }
      |     ^  
      |     abs
fancyfence.cpp:38:9: error: 'find' was not declared in this scope; did you mean 'std::find'?
   38 |  }
      |         ^   
      |         std::find
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: 'std::find' declared here
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
fancyfence.cpp:38:39: error: 'MOD' was not declared in this scope
   38 |  }
      |                                       ^  
fancyfence.cpp:39:19: error: 'ans' was not declared in this scope; did you mean 'abs'?
   39 |  if(ans[find(0)] < 0) ans[find(0)] += MOD;
      |                   ^~~
      |                   abs
fancyfence.cpp:39:23: error: 'find' was not declared in this scope; did you mean 'std::find'?
   39 |  if(ans[find(0)] < 0) ans[find(0)] += MOD;
      |                       ^~~~
      |                       std::find
In file included from /usr/include/c++/10/algorithm:62,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from fancyfence.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:3894:5: note: 'std::find' declared here
 3894 |     find(_InputIterator __first, _InputIterator __last,
      |     ^~~~
fancyfence.cpp:18:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  int N;
      |  ~~~~~^