답안 #541338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
541338 2022-03-23T07:02:56 Z Fidan Addk (eJOI21_addk) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll N = 1000'010;
ll x1, y1;
void upd(ll id, ll val, vector<ll> &v){
	while(id<=v.size()){
		v[id]+=val;
		id+=id&(-id);
	}
}

ll que(ll id, vector<ll> &v){
	ll s=0;
	while(id>0){
		s+=v[id];
		id-=id&(-id);
	}
	return s;
}

ll sum(ll x, ll y, vector<ll> &v){
	x1=x, y1=y;
	return que(y1, v)-que(x1-1, v);
}	

ll prefix(ll x, ll y, vector<ll> &pre, vector<ll> &v){
	x1=x, y1=y;
	return que(y1, pre)-que(x1-1, pre)-(x1-1)*sum(x1, y1, v);
}

ll suffix(ll x, ll y, vector<ll> &pre, vector<ll> &v){
	return (y-x+2)*sum(x, y, v)-prefix(x, y, pre, v);
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	ll n, k, i, y;
	cin>>n>>k;
	
	vector<ll> a(n+1, 0);
	for(i=1; i<=n; i++){
		cin>>a[i];
	}
	
	vector<ll> pre(n+1, 0);
	
	for(i=1; i<=n; i++){
		pre[i]=i*a[i];
	}
	
	ll q;
	cin>>q;
	vector<ll> val(k+1);
	while(q--){
		ll t;
		cin>>t;
		
		if(t==1){
			vector<ll> x(k+1);
			for(i=0; i<k; i++){
				cin>>x[i];
				val[i]=a[x[i]];
			}
			if(k==1) continue;
			x[k]=x[0];
			val[k]=val[0];
			for(i=0; i<k; i++){
				y=x[i];
				upd(y, y*(val[i+1]-val[i]), pre);
				y=x[i];
				upd(y, val[i+1]-val[i], a);
			}
		}
		
		else {
			ll l, r, m, k1 , s=0, b;
			cin>>l>>r>>m;
			k1=r-l+1;
			
			if(k1>=2*m){
				cout<<prefix(l, l+m-1, pre, a)+m*sum(l+m, r-m, a)+suffix(r-m+1, r, pre, a);
			}
			else {
				b=k1-m+1;
				s=prefix(l, l+b-1, pre, a)+b*sum(l+b, r-b, a)+suffix(r-b+1, r, pre, a);
			}
			cout<<s<<endl;
		}
		
	}
	return 0;
}

Compilation message

Main.cpp:6:8: error: 'll y1' redeclared as different kind of entity
    6 | ll x1, y1;
      |        ^~
In file included from /usr/include/features.h:461,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/c++config.h:518,
                 from /usr/include/c++/10/cassert:43,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
                 from Main.cpp:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:221:1: note: previous declaration 'double y1(double)'
  221 | __MATHCALL (y1,, (_Mdouble_));
      | ^~~~~~~~~~
Main.cpp: In function 'void upd(ll, ll, std::vector<long long int>&)':
Main.cpp:8:10: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
    8 |  while(id<=v.size()){
      |        ~~^~~~~~~~~~
Main.cpp: In function 'll sum(ll, ll, std::vector<long long int>&)':
Main.cpp:24:10: error: assignment of function 'double y1(double)'
   24 |  x1=x, y1=y;
      |        ~~^~
Main.cpp:25:13: error: invalid conversion from 'double (*)(double) noexcept' to 'll' {aka 'long long int'} [-fpermissive]
   25 |  return que(y1, v)-que(x1-1, v);
      |             ^~
      |             |
      |             double (*)(double) noexcept
Main.cpp:14:11: note:   initializing argument 1 of 'll que(ll, std::vector<long long int>&)'
   14 | ll que(ll id, vector<ll> &v){
      |        ~~~^~
Main.cpp: In function 'll prefix(ll, ll, std::vector<long long int>&, std::vector<long long int>&)':
Main.cpp:29:10: error: assignment of function 'double y1(double)'
   29 |  x1=x, y1=y;
      |        ~~^~
Main.cpp:30:13: error: invalid conversion from 'double (*)(double) noexcept' to 'll' {aka 'long long int'} [-fpermissive]
   30 |  return que(y1, pre)-que(x1-1, pre)-(x1-1)*sum(x1, y1, v);
      |             ^~
      |             |
      |             double (*)(double) noexcept
Main.cpp:14:11: note:   initializing argument 1 of 'll que(ll, std::vector<long long int>&)'
   14 | ll que(ll id, vector<ll> &v){
      |        ~~~^~
Main.cpp:30:52: error: invalid conversion from 'double (*)(double) noexcept' to 'll' {aka 'long long int'} [-fpermissive]
   30 |  return que(y1, pre)-que(x1-1, pre)-(x1-1)*sum(x1, y1, v);
      |                                                    ^~
      |                                                    |
      |                                                    double (*)(double) noexcept
Main.cpp:23:17: note:   initializing argument 2 of 'll sum(ll, ll, std::vector<long long int>&)'
   23 | ll sum(ll x, ll y, vector<ll> &v){
      |              ~~~^