QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#543857#8524. Weather ForecastHTensorCompile Error//C++174.3kb2024-09-01 22:16:302024-09-01 22:16:30

Judging History

你现在查看的是最新测评结果

  • [2024-09-01 22:16:30]
  • 评测
  • [2024-09-01 22:16:30]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long
using db = long double;
class BIT {
public:
    vector<int> val;
    BIT() { }
    BIT(int n) { val.resize(n + 1); }
    void clear() {
        fill(val.begin(), val.end(), -1);
    }
    int lowbit(int x) { return x & -x; }
	void add(int u, int x) {
		for(int i = u; i < (int)val.size(); i += lowbit(i)) val[i] = max(x, val[i]);
	}

	int query(int u) { 
		int ans = -1; for(int i = u; i; i -= lowbit(i)) ans = max(ans, val[i]); return ans;
	}
};

// results start with 1
void discretize(vector<db>& a) {
    vector<db> b(a);
    sort(b.begin() + 1, b.end());
    b.erase(unique(b.begin() + 1, b.end()), b.end());
    for(int i = 1; i < (int)a.size(); i++) 
        a[i] = lower_bound(b.begin() + 1, b.end(), a[i]) - b.begin();
}

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<int> s(n + 1);
    for (int i = 1; i <= n; i++) {
        s[i] = s[i - 1] + a[i];
    }
    auto check = [&](db m) {
        vector<db> v(n + 2);
        for (int i = 1; i <= n; i++) {
            v[i] = s[i] - i * m;
            // cerr << v[i] << " \n"[i == n];
        }
        discretize(v);
        BIT bit(n + 1);
        bit.add(v[n + 1], 0);
        vector<int> dp(n + 1);
        for (int i = 1; i <= n; i++) {
            dp[i] = bit.query(v[i] - 1) + 1;
            // cerr << i << ": " << v[i] << " " << bit.query(v[i] - 1) << " " << dp[i] << "\n"; 
            bit.add(v[i], dp[i]);
        }
        // for (int i = 1; i <= n; i++) {
        //     cerr << dp[i] << " \n"[i == n];
        // }
        return dp[n] >= k;
    };
    
    // check(1.7);

    db lo = 0, hi = 1000;
    while (hi - lo > 1e-9) {
        db m = (lo + hi) / 2;
        if (check(m)) {
            lo = m;
        } else {
            hi = m;
        }
    }

    cout << fixed << setprecision(10) << (lo + hi) / 2 << "\n";
}
signed main() {
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

/*

*/#include <bits/stdc++.h>
using namespace std;

#define int long long
using db = long double;
class BIT {
public:
    vector<int> val;
    BIT() { }
    BIT(int n) { val.resize(n + 1); }
    void clear() {
        fill(val.begin(), val.end(), -1);
    }
    int lowbit(int x) { return x & -x; }
	void add(int u, int x) {
		for(int i = u; i < (int)val.size(); i += lowbit(i)) val[i] = max(x, val[i]);
	}

	int query(int u) { 
		int ans = -1; for(int i = u; i; i -= lowbit(i)) ans = max(ans, val[i]); return ans;
	}
};

// results start with 1
void discretize(vector<db>& a) {
    vector<db> b(a);
    sort(b.begin() + 1, b.end());
    b.erase(unique(b.begin() + 1, b.end()), b.end());
    for(int i = 1; i < (int)a.size(); i++) 
        a[i] = lower_bound(b.begin() + 1, b.end(), a[i]) - b.begin();
}

void solve() {
    int n, k;
    cin >> n >> k;

    vector<int> a(n + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }

    vector<int> s(n + 1);
    for (int i = 1; i <= n; i++) {
        s[i] = s[i - 1] + a[i];
    }
    auto check = [&](db m) {
        vector<db> v(n + 2);
        for (int i = 1; i <= n; i++) {
            v[i] = s[i] - i * m;
            // cerr << v[i] << " \n"[i == n];
        }
        discretize(v);
        BIT bit(n + 1);
        bit.add(v[n + 1], 0);
        vector<int> dp(n + 1);
        for (int i = 1; i <= n; i++) {
            dp[i] = bit.query(v[i] - 1) + 1;
            // cerr << i << ": " << v[i] << " " << bit.query(v[i] - 1) << " " << dp[i] << "\n"; 
            bit.add(v[i], dp[i]);
        }
        // for (int i = 1; i <= n; i++) {
        //     cerr << dp[i] << " \n"[i == n];
        // }
        return dp[n] >= k;
    };
    
    // check(1.7);

    db lo = 0, hi = 1000;
    while (hi - lo > 1e-9) {
        db m = (lo + hi) / 2;
        if (check(m)) {
            lo = m;
        } else {
            hi = m;
        }
    }

    cout << fixed << setprecision(10) << (lo + hi) / 2 << "\n";
}
signed main() {
    ios::sync_with_stdio(false); 
    cin.tie(nullptr);
    
    int t = 1;
    while (t--) {
        solve();
    }

    return 0;
}

/*

*/

Details

answer.code:100:7: error: redefinition of ‘class BIT’
  100 | class BIT {
      |       ^~~
answer.code:6:7: note: previous definition of ‘class BIT’
    6 | class BIT {
      |       ^~~
answer.code:119:6: error: redefinition of ‘void discretize(std::vector<long double>&)’
  119 | void discretize(vector<db>& a) {
      |      ^~~~~~~~~~
answer.code:25:6: note: ‘void discretize(std::vector<long double>&)’ previously defined here
   25 | void discretize(vector<db>& a) {
      |      ^~~~~~~~~~
answer.code:127:6: error: redefinition of ‘void solve()’
  127 | void solve() {
      |      ^~~~~
answer.code:33:6: note: ‘void solve()’ previously defined here
   33 | void solve() {
      |      ^~~~~
answer.code:175:8: error: redefinition of ‘int main()’
  175 | signed main() {
      |        ^~~~
answer.code:81:8: note: ‘int main()’ previously defined here
   81 | signed main() {
      |        ^~~~