
my code(85 WA):
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const LL keep_time = 86400000;
struct IP{
int page_num;
LL last_exit_time;
string user_name;
IP(){page_num = 0, user_name = "", last_exit_time = 0;}
};
struct User{
string pwd;
set<string> login_ip;
User(){pwd = "", login_ip.clear();}
};
struct Submit_Result{
string name, state;
LL usedtime;
Submit_Result(){name = "", state = "", usedtime = 0;}
Submit_Result(string _name, string _state, LL _usedtime){
name = _name, state = _state, usedtime = _usedtime;
}
bool operator<(const Submit_Result& a) const {
if(state == "AC" && a.state != "AC") return 1;
if(state != "AC" && a.state == "AC") return 0;
return usedtime < a.usedtime;
}
};
struct Ans{
LL time, judge_time, tot_time;
string state, name, question;
Ans(LL _time, LL _judge_time, string _name, string _state, string _question){
time = _time, judge_time = _judge_time, name = _name, state = _state, question = _question;
tot_time = time + judge_time;
}
bool operator<(const Ans& a) const {
return tot_time > a.tot_time;
}
};
priority_queue<Ans> order_submit;
map<string, IP> ip_map;
map<string, User> user_map;
map<string, map<string, string>> user_State;
map<string, set<Submit_Result>> rank_table;
int n;
LL t, judgetime;
string ip, name, pwd, newpwd, question, state, command;
void print_submit(LL t){
while(order_submit.size() && order_submit.top().tot_time <= t){
auto i = order_submit.top();
cout << "[" << i.tot_time << "] USER " << i.name << " " << i.state << " IN " << i.question << '\n';
if(user_State[i.question][i.name] != "AC"){
user_State[i.question][i.name] = i.state;
rank_table[i.question].insert({i.name, i.state, i.time});
}
order_submit.pop();
}
}
int main(){
//freopen("oj.in", "r", stdin);
//freopen("oj.out", "w", stdout);
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
while(n --){
cin >> t >> command >> ip;
print_submit(t);
if(command == "connect"){
if(ip_map[ip].page_num == 0){
cout << "[" << t << "] CONNECTED TO " << ip << '\n';
if(t - ip_map[ip].last_exit_time <= keep_time)
user_map[ip_map[ip].user_name].login_ip.insert(ip);
else ip_map[ip].user_name = "";
}
++ ip_map[ip].page_num;
continue;
}
/*if(ip_map[ip].page_num == 0){
string ex;
getline(cin, ex);
continue;
}*/
if(command == "exit"){
if(ip_map[ip].page_num == 1){
if(ip_map[ip].user_name != "")
user_map[ip_map[ip].user_name].login_ip.erase(ip);
ip_map[ip].last_exit_time = t;
cout << "[" << t << "] CONNECTION TO " << ip << " RELEASED\n";
}
-- ip_map[ip].page_num;
continue;
}
if(command == "register"){
cin >> name >> pwd;
if(ip_map[ip].user_name != "")
cout << "[" << t << "] NOT LOGGED OUT AT " << ip << '\n';
else if(user_map[name].pwd != "")
cout << "[" << t << "] USER " << name << " EXIST\n";
else{
cout << "[" << t << "] USER " << name << " REGISTERED\n";
user_map[name].pwd = pwd;
}
continue;
}
if(command == "login"){
cin >> name >> pwd;
if(ip_map[ip].user_name != "")
cout << "[" << t << "] NOT LOGGED OUT AT " << ip << '\n';
else if(user_map[name].pwd == "")
cout << "[" << t << "] USER " << name << " DO NOT EXIST\n";
else if(user_map[name].pwd != pwd)
cout << "[" << t << "] WRONG PASSWORD\n";
else{
cout << "[" << t << "] USER " << name << " LOGGED IN AT " << ip << '\n';
ip_map[ip].user_name = name;
user_map[name].login_ip.insert(ip);
}
continue;
}
if(ip_map[ip].user_name == ""){
cout << "[" << t << "] NOT LOGGED IN AT " << ip << '\n';
string ex;
getline(cin, ex);
continue;
}
if(command == "change"){
cin >> pwd >> newpwd;
if(user_map[ip_map[ip].user_name].pwd != pwd){
cout << "[" << t << "] WRONG PASSWORD\n";
}
else{
cout << "[" << t << "] PASSWORD CHANGED AT " << ip << '\n';
user_map[ip_map[ip].user_name].pwd = newpwd;
string kname = ip_map[ip].user_name;
for(auto i : user_map[kname].login_ip){
ip_map[i].user_name = "";
}
user_map[kname].login_ip.clear();
}
continue;
}
if(command == "logout"){
cout << "[" << t << "] USER " << ip_map[ip].user_name << " LOGGED OUT AT " << ip << '\n';
user_map[ip_map[ip].user_name].login_ip.erase(ip);
ip_map[ip].user_name = "";
continue;
}
if(command == "submit"){
cin >> question >> state >> judgetime;
order_submit.push({t, judgetime, ip_map[ip].user_name, state, question});
continue;
}
if(command == "rank"){
cin >> name >> question;
if(user_State[question][name] == "")
cout << "[" << t << "] NO SUBMISSION OF USER " << name << " IN " << question << '\n';
else{
LL rank = 1, anstime;
for(Submit_Result i : rank_table[question]){
if(i.name == name){
anstime = i.usedtime;
state = i.state;
break;
}
++ rank;
}
cout << "[" << t << "] RANK OF USER " << name << " IN " << question << ":RANK=" << rank << ",STATE=" << state << ",TIME=" << anstime << '\n';
}
continue;
}
}
print_submit(t);
return 0;
}