답안 #725277

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725277 2023-04-17T06:26:48 Z Baytoro Pairs (IOI07_pairs) C++17
70 / 100
4000 ms 3796 KB
#include <bits/stdc++.h>
using namespace std;
#define ios ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define endl '\n'
#define ll long long
#define int long long
void fopn(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const ll INF=1e18,mod=1e9+9,N=1e5+5;
template<class T, int... Ns> struct BIT {
    T val = 0;
    void upd(T v) { val += v; }
    T query() { return val; }  
};
template<class T, int N, int... Ns> struct BIT<T, N, Ns...> {
    BIT<T, Ns...> bit[N+1];
    template<typename... Args> void upd(int pos, Args... args) {
        for (; pos <= N; pos += pos&-pos) bit[pos].upd(args...);
    }
    template<typename... Args> T sum(int pos, Args... args) {
        T res = 0; for (; pos > 0; pos -= pos&-pos) res += bit[pos].query(args...);
        return res;
    }
    template<typename... Args> T query(int l, int r, Args... args) {
        return sum(r, args...) - sum(l-1, args...);
    }
};
struct triple{
	int x,y,z;
};
void solve(){
	int b,n,d,m;
	cin>>b>>n>>d>>m;
	if(b==1){
		vector<int> a(n);
		for(int i=0;i<n;i++) cin>>a[i];
		sort(all(a));
		int ans=0;
		for(int i=0;i<n;i++){
			int j=upper_bound(all(a),a[i]+d)-a.begin();
			ans+=j-i-1;
		}
		cout<<ans<<endl;
	}
	else if(b==2){
		vector<pair<int,int>> a(n);
		for(int i=0;i<n;i++){
			int x,y;cin>>x>>y;
			a[i]={x+y,x-y};
		}
		sort(all(a));
		int ans=0;
		BIT<int,150005> bit;
		
		int l=0,r=-1;
		for(int i=0;i<n;i++){
			while(r+1<n && a[r+1].fr-a[i].fr<=d)
				bit.upd(a[++r].sc+m+1,1);
			while(l<n && a[i].fr-a[l].fr>d)
				bit.upd(a[l++].sc+m+1,-1);
			ans+=bit.query(max(1ll,a[i].sc+m+1-d),min(2*m+1,a[i].sc+m+1+d))-1;
			
		}
		cout<<ans/2<<endl;
	}
	else{
		vector<triple> a(n);
		for(int i=0;i<n;i++){
			cin>>a[i].x>>a[i].y>>a[i].z;
		}
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=i+1;j<n;j++){
				if(abs(a[i].x-a[j].x)+abs(a[i].y-a[j].y)+abs(a[i].z-a[j].z)<=d) ans++;
			}
		}
		cout<<ans<<endl;
	}
}
main(){
	//fopn("team");
	ios;
	int T=1;
	//cin>>T;
	for(int i=1;i<=T;i++){
		//cout<<"Case #"<<i<<": ";
		solve();
	}
}

Compilation message

pairs.cpp:87:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   87 | main(){
      | ^~~~
pairs.cpp: In function 'void fopn(std::string)':
pairs.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
pairs.cpp:14:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1364 KB Output is correct
2 Correct 1 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2260 KB Output is correct
2 Correct 15 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2260 KB Output is correct
2 Correct 20 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 2260 KB Output is correct
2 Correct 24 ms 2260 KB Output is correct
3 Correct 25 ms 2260 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 2976 KB Output is correct
2 Correct 24 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 3028 KB Output is correct
2 Correct 30 ms 3028 KB Output is correct
3 Correct 29 ms 3028 KB Output is correct
4 Correct 36 ms 3068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 3028 KB Output is correct
2 Correct 31 ms 3028 KB Output is correct
3 Correct 30 ms 3028 KB Output is correct
4 Correct 31 ms 3028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1492 KB Output is correct
2 Correct 2 ms 1492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4025 ms 3796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4035 ms 3796 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 4070 ms 3796 KB Time limit exceeded
2 Halted 0 ms 0 KB -