QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#318140#3558. Constellation 3tojCompile Error//C++171.3kb2024-01-30 16:21:052024-01-30 16:21:06

Judging History

This is the latest submission verdict.

  • [2024-01-30 16:21:06]
  • Judged
  • [2024-01-30 16:21:05]
  • Submitted

answer

// S2OJ Submission #1172 @ 1706602864977
//TOJ#156 Constellation 3
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
struct dsu{
	vector<int> next(n+2);
	dfs(int n):next(n+2){
		for(int i=0;i<=n+1;i++){
			next[i]=i;
		}
	}
	int find(int x){
		return next[x]==x?x:next[x]=find(next[x]);
	}
}; 

struct fenwick{
	vector<long long> a;
	fenwick(int n):a(n+1){
	}
	long long sum(int i){
		long long ans=0l
		while(i>0) ans+=a[i],i-=i&-i;
		return ans;
	}
	void add(int i,long long x){
		while(i<a.size()){
			a[i]+=x;
			i+=i&-i;
		}
	}
};

int main(){
	int n;
	cin>>n;
	vector<vector<int> > z(n+1);
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		z[a].push_back(i);
	}
	int m;
	cin>>m;
	vector<vector<pair<int,int> > > star(n+1); 
	for(int i=0;i<m;i++){
		int x,y,c;
		cin>>x>>y>>c;
		star[y].push_back({x,c});
	}
	fenwick cost(n);
	dsu L(n),R(n);
	long long ans=0;
	for(int y=1;y<=n;y++){
		for(auto s:star[y]){
			int x=s.first,c=s.second;
			long long C=cost.sum(x);
			if(c<=C) ans+=c;
			else{
				ans+=C;
				//反悔选项 
				int l=L.find(x),r=R.find(x);
				cost.add(l+1,c-C);
				cost.add(r,C-c)
			}
		}
		//让不再起作用的柱子消失
		for(int x:z[y]){
			L.next[x]=x-1;
			R=next[x]=x+1;
		} 
	}
	cout<<ans<<endl;
	return 0;
}

Details

answer.code:7:26: error: ‘n’ has not been declared
    7 |         vector<int> next(n+2);
      |                          ^
answer.code:7:27: error: expected ‘,’ or ‘...’ before ‘+’ token
    7 |         vector<int> next(n+2);
      |                           ^
answer.code:8:9: error: ISO C++ forbids declaration of ‘dfs’ with no type [-fpermissive]
    8 |         dfs(int n):next(n+2){
      |         ^~~
answer.code: In member function ‘int dsu::dfs(int)’:
answer.code:8:20: error: only constructors take member initializers
    8 |         dfs(int n):next(n+2){
      |                    ^~~~
answer.code:8:20: error: class ‘dsu’ does not have any field named ‘next’
answer.code:10:29: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   10 |                         next[i]=i;
      |                             ^
answer.code:12:9: warning: no return statement in function returning non-void [-Wreturn-type]
   12 |         }
      |         ^
answer.code: In member function ‘int dsu::find(int)’:
answer.code:14:28: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   14 |                 return next[x]==x?x:next[x]=find(next[x]);
      |                            ^
answer.code:14:41: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   14 |                 return next[x]==x?x:next[x]=find(next[x]);
      |                                         ^
answer.code:14:54: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   14 |                 return next[x]==x?x:next[x]=find(next[x]);
      |                                                      ^
answer.code: In member function ‘long long int fenwick::sum(int)’:
answer.code:24:17: error: expected ‘,’ or ‘;’ before ‘while’
   24 |                 while(i>0) ans+=a[i],i-=i&-i;
      |                 ^~~~~
answer.code: In function ‘int main()’:
answer.code:53:16: error: no matching function for call to ‘dsu::dsu(int&)’
   53 |         dsu L(n),R(n);
      |                ^
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu()’
    6 | struct dsu{
      |        ^~~
answer.code:6:8: note:   candidate expects 0 arguments, 1 provided
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu(const dsu&)’
answer.code:6:8: note:   no known conversion for argument 1 from ‘int’ to ‘const dsu&’
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu(dsu&&)’
answer.code:6:8: note:   no known conversion for argument 1 from ‘int’ to ‘dsu&&’
answer.code:53:21: error: no matching function for call to ‘dsu::dsu(int&)’
   53 |         dsu L(n),R(n);
      |                     ^
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu()’
    6 | struct dsu{
      |        ^~~
answer.code:6:8: note:   candidate expects 0 arguments, 1 provided
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu(const dsu&)’
answer.code:6:8: note:   no known conversion for argument 1 from ‘int’ to ‘const dsu&’
answer.code:6:8: note: candidate: ‘constexpr dsu::dsu(dsu&&)’
answer.code:6:8: note:   no known conversion for argument 1 from ‘int’ to ‘dsu&&’
answer.code:65:48: error: expected ‘;’ before ‘}’ token
   65 |                                 cost.add(r,C-c)
      |                                                ^
      |                                                ;
   66 |                         }
      |                         ~                       
answer.code:70:31: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   70 |                         L.next[x]=x-1;
      |                               ^
answer.code:71:31: error: invalid types ‘<unresolved overloaded function type>[int]’ for array subscript
   71 |                         R=next[x]=x+1;
      |                               ^